blob: ec0c213535d9c924405f56987a8e4b043dc58f0f [file] [log] [blame]
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001/*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * Copyright (c) 2011-2014, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Patrick Benavoli68a91282011-08-31 11:23:23 +020029 */
30#include "ConfigurableDomain.h"
31#include "DomainConfiguration.h"
32#include "ConfigurableElement.h"
33#include "ConfigurationAccessContext.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020034#include "XmlDomainSerializingContext.h"
35#include <assert.h>
36
37#define base CBinarySerializableElement
38
Patrick Benavoli63499d42011-10-24 18:50:03 +020039CConfigurableDomain::CConfigurableDomain(const string& strName) : base(strName), _bSequenceAware(false), _pLastAppliedConfiguration(NULL)
Patrick Benavoli68a91282011-08-31 11:23:23 +020040{
41}
42
43CConfigurableDomain::~CConfigurableDomain()
44{
Patrick Benavoli63499d42011-10-24 18:50:03 +020045 // Remove all configurable elements
Patrick Benavoli68a91282011-08-31 11:23:23 +020046 ConfigurableElementListIterator it;
47
Patrick Benavoli68a91282011-08-31 11:23:23 +020048 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
49
50 CConfigurableElement* pConfigurableElement = *it;
51
52 // Remove from configurable element
53 pConfigurableElement->removeAttachedConfigurableDomain(this);
54 }
Patrick Benavoli63499d42011-10-24 18:50:03 +020055
56 // Remove all associated syncer sets
57 ConfigurableElementToSyncerSetMapIterator mapIt;
58
59 for (mapIt = _configurableElementToSyncerSetMap.begin(); mapIt != _configurableElementToSyncerSetMap.end(); ++mapIt) {
60
61 delete mapIt->second;
62 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020063}
64
65string CConfigurableDomain::getKind() const
66{
67 return "ConfigurableDomain";
68}
69
70bool CConfigurableDomain::childrenAreDynamic() const
71{
72 return true;
73}
74
Patrick Benavoli0bd50542011-11-29 11:10:27 +010075// Content dumping
76void CConfigurableDomain::logValue(string& strValue, CErrorContext& errorContext) const
77{
78 (void)errorContext;
79
80 strValue = "{";
81
82 // Sequence awareness
83 strValue += "Sequence aware: ";
84 strValue += _bSequenceAware ? "yes" : "no";
85
86 // Last applied configuration
87 strValue += ", Last applied configuration: ";
88 strValue += _pLastAppliedConfiguration ? _pLastAppliedConfiguration->getName() : "<none>";
89
90 strValue += "}";
91}
92
Patrick Benavoli63499d42011-10-24 18:50:03 +020093// Sequence awareness
94void CConfigurableDomain::setSequenceAwareness(bool bSequenceAware)
95{
96 if (_bSequenceAware != bSequenceAware) {
97
Kevin Rocardace81f82012-12-11 16:19:17 +010098 log_info("Making domain \"%s\" sequence %s", getName().c_str(), bSequenceAware ? "aware" : "unaware");
Patrick Benavoli63499d42011-10-24 18:50:03 +020099
100 _bSequenceAware = bSequenceAware;
101 }
102}
103
104bool CConfigurableDomain::getSequenceAwareness() const
105{
106 return _bSequenceAware;
107}
108
Patrick Benavoli68a91282011-08-31 11:23:23 +0200109// From IXmlSource
110void CConfigurableDomain::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
111{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200112 // Sequence awareness
113 xmlElement.setAttributeBoolean("SequenceAware", _bSequenceAware);
114
Patrick Benavoli68a91282011-08-31 11:23:23 +0200115 // Configurations
116 composeDomainConfigurations(xmlElement, serializingContext);
117
118 // Configurable Elements
Patrick Benavoli63499d42011-10-24 18:50:03 +0200119 composeConfigurableElements(xmlElement);
120
121 // Settings
122 composeSettings(xmlElement, serializingContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200123}
124
125// XML composing
126void CConfigurableDomain::composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
127{
128 // Create Configurations element
129 CXmlElement xmlConfigurationsElement;
130
131 xmlElement.createChild(xmlConfigurationsElement, "Configurations");
132
133 // Delegate to base
134 base::toXml(xmlConfigurationsElement, serializingContext);
135}
136
Patrick Benavoli63499d42011-10-24 18:50:03 +0200137void CConfigurableDomain::composeConfigurableElements(CXmlElement& xmlElement) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200138{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200139 // Create ConfigurableElements element
140 CXmlElement xmlConfigurableElementsElement;
141
142 xmlElement.createChild(xmlConfigurableElementsElement, "ConfigurableElements");
143
144 // Serialize out all configurable elements settings
145 ConfigurableElementListIterator it;
146
147 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
148
149 const CConfigurableElement* pConfigurableElement = *it;
150
151 // Create corresponding XML child element
152 CXmlElement xmlChildConfigurableElement;
153
154 xmlConfigurableElementsElement.createChild(xmlChildConfigurableElement, "ConfigurableElement");
155
156 // Set Path attribute
157 xmlChildConfigurableElement.setAttributeString("Path", pConfigurableElement->getPath());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200158 }
159}
160
Patrick Benavoli63499d42011-10-24 18:50:03 +0200161void CConfigurableDomain::composeSettings(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200162{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200163 // Context
164 const CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<const CXmlDomainSerializingContext&>(serializingContext);
165
166 if (!xmlDomainSerializingContext.withSettings()) {
167
168 return;
169 }
170
171 // Create Settings element
172 CXmlElement xmlSettingsElement;
173
174 xmlElement.createChild(xmlSettingsElement, "Settings");
175
176 // Serialize out all configurations settings
Patrick Benavoli68a91282011-08-31 11:23:23 +0200177 uint32_t uiNbConfigurations = getNbChildren();
178 uint32_t uiChildConfiguration;
179
180 for (uiChildConfiguration = 0; uiChildConfiguration < uiNbConfigurations; uiChildConfiguration++) {
181
182 const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChildConfiguration));
183
184 // Create child xml element for that configuration
185 CXmlElement xmlConfigurationSettingsElement;
186
Patrick Benavoli63499d42011-10-24 18:50:03 +0200187 xmlSettingsElement.createChild(xmlConfigurationSettingsElement, pDomainConfiguration->getKind());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200188
189 // Set its name attribute
190 xmlConfigurationSettingsElement.setNameAttribute(pDomainConfiguration->getName());
191
Patrick Benavoli63499d42011-10-24 18:50:03 +0200192 // Serialize out configuration settings
193 pDomainConfiguration->composeSettings(xmlConfigurationSettingsElement, serializingContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200194 }
195}
196
197// From IXmlSink
198bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
199{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200200 // Context
201 CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<CXmlDomainSerializingContext&>(serializingContext);
202
203 // Sequence awareness (optional)
204 _bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware");
205
Patrick Benavoli68a91282011-08-31 11:23:23 +0200206 // Local parsing. Do not dig
Patrick Benavoli63499d42011-10-24 18:50:03 +0200207 if (!parseDomainConfigurations(xmlElement, serializingContext) || !parseConfigurableElements(xmlElement, serializingContext) || !parseSettings(xmlElement, serializingContext)) {
208
209 return false;
210 }
211
212 // All provided configurations are parsed
213 // Attempt validation on areas of non provided configurations for all configurable elements if required
214 if (xmlDomainSerializingContext.autoValidationRequired()) {
215
216 autoValidateAll();
217 }
218
219 return true;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200220}
221
222// XML parsing
223bool CConfigurableDomain::parseDomainConfigurations(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
224{
225 // We're supposedly clean
226 assert(_configurableElementList.empty());
227
228 // Get Configurations element
229 CXmlElement xmlConfigurationsElement;
230
231 xmlElement.getChildElement("Configurations", xmlConfigurationsElement);
232
233 // Parse it and create domain configuration objects
234 return base::fromXml(xmlConfigurationsElement, serializingContext);
235}
236
237// Parse configurable elements
238bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
239{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200240 // Get System Class Element
241 CElement* pRootElement = getRoot();
242
243 CElement* pSystemClassElement = pRootElement->findChildOfKind("SystemClass");
244
245 assert(pSystemClassElement);
246
247 // Get ConfigurableElements element
248 CXmlElement xmlConfigurableElementsElement;
249 xmlElement.getChildElement("ConfigurableElements", xmlConfigurableElementsElement);
250
251 // Parse it and associate found configurable elements to it
252 CXmlElement::CChildIterator it(xmlConfigurableElementsElement);
253
254 CXmlElement xmlConfigurableElementElement;
255
256 while (it.next(xmlConfigurableElementElement)) {
257
258 // Locate configurable element
259 string strConfigurableElementPath = xmlConfigurableElementElement.getAttributeString("Path");
260
261 CPathNavigator pathNavigator(strConfigurableElementPath);
Patrick Benavoli065264a2011-11-20 15:46:41 +0100262 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200263
264 // Is there an element and does it match system class name?
Patrick Benavoli065264a2011-11-20 15:46:41 +0100265 if (!pathNavigator.navigateThrough(pSystemClassElement->getName(), strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200266
Patrick Benavoli065264a2011-11-20 15:46:41 +0100267 serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName() + " (" + strError + ")");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200268
269 return false;
270 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200271 // Browse system class for configurable element
272 CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pSystemClassElement->findDescendant(pathNavigator));
273
274 if (!pConfigurableElement) {
275
276 serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName());
277
278 return false;
279 }
280 // Add found element to domain
Patrick Benavoli68a91282011-08-31 11:23:23 +0200281 if (!addConfigurableElement(pConfigurableElement, NULL, strError)) {
282
283 serializingContext.setError(strError);
284
285 return false;
286 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200287 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200288
289 return true;
290}
291
Patrick Benavoli63499d42011-10-24 18:50:03 +0200292// Parse settings
293bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
Patrick Benavoli68a91282011-08-31 11:23:23 +0200294{
295 // Context
296 CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<CXmlDomainSerializingContext&>(serializingContext);
297
Patrick Benavoli63499d42011-10-24 18:50:03 +0200298 // Check we actually need to parse configuration settings
299 if (!xmlDomainSerializingContext.withSettings()) {
300
301 // No parsing required
302 return true;
303 }
304
305 // Get Settings element
306 CXmlElement xmlSettingsElement;
307 if (!xmlElement.getChildElement("Settings", xmlSettingsElement)) {
308
309 // No settings, bail out successfully
310 return true;
311 }
312
313 // Parse configuration settings
314 CXmlElement::CChildIterator it(xmlSettingsElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200315
316 CXmlElement xmlConfigurationSettingsElement;
317
318 while (it.next(xmlConfigurationSettingsElement)) {
319 // Get domain configuration
320 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(xmlConfigurationSettingsElement.getNameAttribute()));
321
322 if (!pDomainConfiguration) {
323
Patrick Benavoli63499d42011-10-24 18:50:03 +0200324 xmlDomainSerializingContext.setError("Could not find domain configuration referred to by configurable domain " + getName());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200325
326 return false;
327 }
Patrick Benavoli63499d42011-10-24 18:50:03 +0200328 // Have domain configuration parse settings for all configurable elements
329 if (!pDomainConfiguration->parseSettings(xmlConfigurationSettingsElement, xmlDomainSerializingContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200330
331 return false;
332 }
333 }
334
335 return true;
336}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200337// Configurable elements association
338bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError)
339{
340 // Already associated?
341 if (containsConfigurableElement(pConfigurableElement)) {
342
343 strError = "Configurable element " + pConfigurableElement->getPath() + " already associated to configuration domain " + getName();
344
345 return false;
346 }
347
348 // Already owned?
349 if (pConfigurableElement->belongsTo(this)) {
350
351 strError = "Configurable element " + pConfigurableElement->getPath() + " already owned by configuration domain " + getName();
352
353 return false;
354 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200355
356 // Do add
Frédéric Boisnard9620e442012-05-30 16:15:02 +0200357 doAddConfigurableElement(pConfigurableElement, pMainBlackboard);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358
359 return true;
360}
361
362bool CConfigurableDomain::removeConfigurableElement(CConfigurableElement* pConfigurableElement, string& strError)
363{
364 // Not associated?
365 if (!containsConfigurableElement(pConfigurableElement)) {
366
367 strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName();
368
369 return false;
370 }
Kevin Rocardace81f82012-12-11 16:19:17 +0100371 log_info("Removing configurable element \"%s\" from domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200372
373 // Do remove
374 doRemoveConfigurableElement(pConfigurableElement, true);
375
376 return true;
377}
378
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +0100379/**
380* Blackboard Configuration and Base Offset retrieval.
381*
382* This method fetches the Blackboard associated to the ConfigurableElement
383* given in parameter, for a specific Configuration. The ConfigurableElement
384* must belong to the Domain. If a Blackboard is found, the base offset of
385* the ConfigurableElement is returned as well. This base offset corresponds to
386* the offset of the ancestor of the ConfigurableElement associated to the Configuration.
387*
388* @param[in] strConfiguration Name of the Configuration.
389* @param[in] pCandidateDescendantConfigurableElement Pointer to a CConfigurableElement that
390* belongs to the Domain.
391* @param[out] uiBaseOffset The base offset of the CConfigurableElement.
392* @param[out] bIsLastApplied Boolean indicating that the Configuration is
393* the last one applied of the Domain.
394* @param[out] strError Error message
395*
396* return Pointer to the Blackboard of the Configuration.
397*/
398CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const string& strConfiguration,
399 const CConfigurableElement* pCandidateDescendantConfigurableElement,
400 uint32_t& uiBaseOffset,
401 bool& bIsLastApplied,
402 string& strError) const
403{
404 // Find Configuration
405 const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration));
406
407 if (!pDomainConfiguration) {
408
409 strError = "Domain configuration " + strConfiguration + " not found";
410
411 return NULL;
412 }
413
414 // Parse all configurable elements
415 ConfigurableElementListIterator it;
416
417 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
418
419 const CConfigurableElement* pAssociatedConfigurableElement = *it;
420
421 // Check if the the associated element is the configurable element or one of its ancestors
422 if ((pCandidateDescendantConfigurableElement == pAssociatedConfigurableElement) ||
423 (pCandidateDescendantConfigurableElement->isDescendantOf(pAssociatedConfigurableElement))) {
424
425 uiBaseOffset = pAssociatedConfigurableElement->getOffset();
426 bIsLastApplied = (pDomainConfiguration == _pLastAppliedConfiguration);
427
428 return pDomainConfiguration->getBlackboard(pAssociatedConfigurableElement);
429 }
430 }
431
432 strError = "Element not associated to the Domain";
433
434 return NULL;
435}
436
Patrick Benavoli68a91282011-08-31 11:23:23 +0200437// Domain splitting
438bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, string& strError)
439{
440 // Not associated?
441 if (!containsConfigurableElement(pConfigurableElement)) {
442
443 strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName();
444
445 return false;
446 }
Kevin Rocardace81f82012-12-11 16:19:17 +0100447 log_info("Splitting configurable element \"%s\" domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200448
449 // Create sub domain areas for all configurable element's children
450 uint32_t uiNbConfigurableElementChildren = pConfigurableElement->getNbChildren();
451
452 if (!uiNbConfigurableElementChildren) {
453
454 strError = "Configurable element " + pConfigurableElement->getPath() + " has no children to split configurable domain to";
455
456 return false;
457 }
458
459 uint32_t uiChild;
460
461 for (uiChild = 0; uiChild < uiNbConfigurableElementChildren; uiChild++) {
462
463 CConfigurableElement* pChildConfigurableElement = static_cast<CConfigurableElement*>(pConfigurableElement->getChild(uiChild));
464
465 doAddConfigurableElement(pChildConfigurableElement);
466 }
467
468 // Delegate to configurations
469 uint32_t uiNbConfigurations = getNbChildren();
470
471 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
472
473 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
474
475 pDomainConfiguration->split(pConfigurableElement);
476 }
477
478 // Remove given configurable element from this domain
479 // Note: we shouldn't need to recompute the sync set in that case, as the splitted element should include the syncers of its children elements
480 doRemoveConfigurableElement(pConfigurableElement, false);
481
482 return true;
483}
484
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200485// Check if there is a pending configuration for this domain: i.e. an applicable configuration different from the last applied configuration
486const CDomainConfiguration* CConfigurableDomain::getPendingConfiguration() const
487{
488 const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration();
489
490 if (pApplicableDomainConfiguration) {
491
492 // Check not the last one before applying
493 if (!_pLastAppliedConfiguration || (_pLastAppliedConfiguration != pApplicableDomainConfiguration)) {
494
495 return pApplicableDomainConfiguration;
496 }
497 }
498
499 return NULL;
500}
501
Patrick Benavoli68a91282011-08-31 11:23:23 +0200502// Configuration application if required
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100503void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForce) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200504{
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100505 // Apply configuration only if the blackboard will
506 // be synchronized either now or by syncerSet.
507 if(!pSyncerSet ^ _bSequenceAware) {
508 // The configuration can not be syncronised
509 return;
510 }
511
Patrick Benavoli68a91282011-08-31 11:23:23 +0200512 if (bForce) {
513 // Force a configuration restore by forgetting about last applied configuration
514 _pLastAppliedConfiguration = NULL;
515 }
516 const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration();
517
518 if (pApplicableDomainConfiguration) {
519
520 // Check not the last one before applying
521 if (!_pLastAppliedConfiguration || _pLastAppliedConfiguration != pApplicableDomainConfiguration) {
522
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100523 log_info("Applying configuration \"%s\" from domain \"%s\"",
524 pApplicableDomainConfiguration->getName().c_str(),
525 getName().c_str());
526
527 // Check if we need to synchronize during restore
528 bool bSync = !pSyncerSet && _bSequenceAware;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200529
530 // Do the restore
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100531 pApplicableDomainConfiguration->restore(pParameterBlackboard, bSync, NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200532
533 // Record last applied configuration
534 _pLastAppliedConfiguration = pApplicableDomainConfiguration;
535
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100536 // Check we need to provide syncer set to caller
537 if (pSyncerSet && !_bSequenceAware) {
Patrick Benavoli63499d42011-10-24 18:50:03 +0200538
539 // Since we applied changes, add our own sync set to the given one
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +0100540 *pSyncerSet += _syncerSet;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200541 }
Patrick Benavoli68a91282011-08-31 11:23:23 +0200542 }
543 }
544}
545
546// Return applicable configuration validity for given configurable element
547bool CConfigurableDomain::isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const
548{
549 const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration();
550
551 return pApplicableDomainConfiguration && pApplicableDomainConfiguration->isValid(pConfigurableElement);
552}
553
Patrick Benavoli68a91282011-08-31 11:23:23 +0200554// In case configurable element was removed
555void CConfigurableDomain::computeSyncSet()
556{
557 // Clean sync set first
Patrick Benavoli63499d42011-10-24 18:50:03 +0200558 _syncerSet.clear();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200559
Patrick Benavoli63499d42011-10-24 18:50:03 +0200560 // Add syncer sets for all associated configurable elements
561 ConfigurableElementToSyncerSetMapIterator mapIt;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200562
Patrick Benavoli63499d42011-10-24 18:50:03 +0200563 for (mapIt = _configurableElementToSyncerSetMap.begin(); mapIt != _configurableElementToSyncerSetMap.end(); ++mapIt) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200564
Patrick Benavoli63499d42011-10-24 18:50:03 +0200565 const CSyncerSet* pSyncerSet = mapIt->second;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200566
Patrick Benavoli63499d42011-10-24 18:50:03 +0200567 _syncerSet += *pSyncerSet;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200568 }
569}
570
571// Configuration Management
572bool CConfigurableDomain::createConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError)
573{
574 // Already exists?
575 if (findChild(strName)) {
576
577 strError = "Already existing configuration";
578
579 return false;
580 }
Kevin Rocardace81f82012-12-11 16:19:17 +0100581 log_info("Creating domain configuration \"%s\" into domain \"%s\"", strName.c_str(), getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200582
583 // Creation
584 CDomainConfiguration* pDomainConfiguration = new CDomainConfiguration(strName);
585
586 // Configurable elements association
587 ConfigurableElementListIterator it;
588
589 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
590
Patrick Benavoli63499d42011-10-24 18:50:03 +0200591 const CConfigurableElement* pConfigurableElement = *it;;
592
593 // Retrieve associated syncer set
594 CSyncerSet* pSyncerSet = getSyncerSet(pConfigurableElement);
595
596 // Associate to configuration
597 pDomainConfiguration->addConfigurableElement(pConfigurableElement, pSyncerSet);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200598 }
599
600 // Hierarchy
601 addChild(pDomainConfiguration);
602
603 // Ensure validity of fresh new domain configuration
604 // Attempt auto validation, so that the user gets his/her own settings by defaults
605 if (!autoValidateConfiguration(pDomainConfiguration)) {
606
607 // No valid configuration found to copy in from, validate againt main blackboard (will concerned remaining invalid parts)
608 pDomainConfiguration->validate(pMainBlackboard);
609 }
610
611 return true;
612}
613
614bool CConfigurableDomain::deleteConfiguration(const string& strName, string& strError)
615{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100616 CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200617
618 if (!pDomainConfiguration) {
619
Patrick Benavoli68a91282011-08-31 11:23:23 +0200620 return false;
621 }
622
Kevin Rocardace81f82012-12-11 16:19:17 +0100623 log_info("Deleting configuration \"%s\" from domain \"%s\"", strName.c_str(), getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200624
625 // Was the last applied?
626 if (pDomainConfiguration == _pLastAppliedConfiguration) {
627
628 // Forget about it
629 _pLastAppliedConfiguration = NULL;
630 }
631
632 // Hierarchy
633 removeChild(pDomainConfiguration);
634
635 // Destroy
636 delete pDomainConfiguration;
637
638 return true;
639}
640
641void CConfigurableDomain::listAssociatedToElements(string& strResult) const
642{
643 strResult = "\n";
644
645 ConfigurableElementListIterator it;
646
647 // Browse all configurable elements
648 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
649
650 const CConfigurableElement* pConfigurableElement = *it;
651
652 strResult += pConfigurableElement->getPath() + "\n";
653 }
654}
655
656bool CConfigurableDomain::renameConfiguration(const string& strName, const string& strNewName, string& strError)
657{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100658 CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200659
660 if (!pDomainConfiguration) {
661
Patrick Benavoli68a91282011-08-31 11:23:23 +0200662 return false;
663 }
Kevin Rocardace81f82012-12-11 16:19:17 +0100664 log_info("Renaming domain \"%s\"'s configuration \"%s\" to \"%s\"", getName().c_str(), strName.c_str(), strNewName.c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200665
666 // Rename
667 return pDomainConfiguration->rename(strNewName, strError);
668}
669
Kevin Rocardace81f82012-12-11 16:19:17 +0100670bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, list<string>& lstrError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200671{
Kevin Rocardace81f82012-12-11 16:19:17 +0100672 string strError;
673
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100674 const CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200675
676 if (!pDomainConfiguration) {
677
Kevin Rocardace81f82012-12-11 16:19:17 +0100678 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200679 return false;
680 }
Kevin Rocardace81f82012-12-11 16:19:17 +0100681 log_info("Restoring domain \"%s\"'s configuration \"%s\" to parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200682
683 // Delegate
Kevin Rocardace81f82012-12-11 16:19:17 +0100684 bool bSuccess = pDomainConfiguration->restore(pMainBlackboard, bAutoSync && _bSequenceAware, &lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200685
686 // Record last applied configuration
687 _pLastAppliedConfiguration = pDomainConfiguration;
688
689 // Synchronize
Kevin Rocardace81f82012-12-11 16:19:17 +0100690 if (bAutoSync && !_bSequenceAware) {
691
692 bSuccess &= _syncerSet.sync(*pMainBlackboard, false, &lstrError);
693 }
694 return bSuccess;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200695}
696
697bool CConfigurableDomain::saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError)
698{
699 // Find Domain configuration
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100700 CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200701
702 if (!pDomainConfiguration) {
703
Patrick Benavoli68a91282011-08-31 11:23:23 +0200704 return false;
705 }
Kevin Rocardace81f82012-12-11 16:19:17 +0100706 log_info("Saving domain \"%s\"'s configuration \"%s\" from parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200707
708 // Delegate
709 pDomainConfiguration->save(pMainBlackboard);
710
711 return true;
712}
713
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100714bool CConfigurableDomain::setElementSequence(const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError)
Patrick Benavoli63499d42011-10-24 18:50:03 +0200715{
716 // Find Domain configuration
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100717 CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200718
719 if (!pDomainConfiguration) {
720
Patrick Benavoli63499d42011-10-24 18:50:03 +0200721 return false;
722 }
723
724 // Delegate to configuration
725 return pDomainConfiguration->setElementSequence(astrNewElementSequence, strError);
726}
727
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100728bool CConfigurableDomain::getElementSequence(const string& strConfiguration, string& strResult) const
Patrick Benavoli63499d42011-10-24 18:50:03 +0200729{
730 // Find Domain configuration
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100731 const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200732
733 if (!pDomainConfiguration) {
734
Patrick Benavoli63499d42011-10-24 18:50:03 +0200735 return false;
736 }
737
738 // Delegate to configuration
739 pDomainConfiguration->getElementSequence(strResult);
740
741 return true;
742}
743
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100744bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError)
745{
746 // Find Domain configuration
747 CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError);
748
749 if (!pDomainConfiguration) {
750
751 return false;
752 }
753
754 // Delegate to configuration
755 return pDomainConfiguration->setApplicationRule(strApplicationRule, pSelectionCriteriaDefinition, strError);
756}
757
758bool CConfigurableDomain::clearApplicationRule(const string& strConfiguration, string& strError)
759{
760 // Find Domain configuration
761 CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError);
762
763 if (!pDomainConfiguration) {
764
765 return false;
766 }
767
768 // Delegate to configuration
769 pDomainConfiguration->clearApplicationRule();
770
771 return true;
772}
773
774bool CConfigurableDomain::getApplicationRule(const string& strConfiguration, string& strResult) const
775{
776 // Find Domain configuration
777 const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult);
778
779 if (!pDomainConfiguration) {
780
781 return false;
782 }
783
784 // Delegate to configuration
785 pDomainConfiguration->getApplicationRule(strResult);
786
787 return true;
788}
789
Patrick Benavoli68a91282011-08-31 11:23:23 +0200790// Last applied configuration
791string CConfigurableDomain::getLastAppliedConfigurationName() const
792{
793 if (_pLastAppliedConfiguration) {
794
795 return _pLastAppliedConfiguration->getName();
796 }
797 return "<none>";
798}
799
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200800// Pending configuration
801string CConfigurableDomain::getPendingConfigurationName() const
802{
803 const CDomainConfiguration* pPendingConfiguration = getPendingConfiguration();
804
805 if (pPendingConfiguration) {
806
807 return pPendingConfiguration->getName();
808 }
809 return "<none>";
810}
811
Patrick Benavoli68a91282011-08-31 11:23:23 +0200812// Ensure validity on whole domain from main blackboard
813void CConfigurableDomain::validate(const CParameterBlackboard* pMainBlackboard)
814{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200815
816 // Propagate
817 uint32_t uiNbConfigurations = getNbChildren();
818 uint32_t uiChild;
819
820 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
821
822 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
823
824 pDomainConfiguration->validate(pMainBlackboard);
825 }
826}
827
828// Ensure validity on areas related to configurable element
829void CConfigurableDomain::validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard)
830{
Kevin Rocardace81f82012-12-11 16:19:17 +0100831 log_info("Validating domain \"" + getName() + "\" against main blackboard for configurable element \"" + pConfigurableElement->getPath() + "\"");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200832
833 // Propagate
834 uint32_t uiNbConfigurations = getNbChildren();
835 uint32_t uiChild;
836
837 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
838
839 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
840
841 pDomainConfiguration->validate(pConfigurableElement, pMainBlackboard);
842 }
843}
844
845// Attempt validation for all configurable element's areas, relying on already existing valid configuration inside domain
846void CConfigurableDomain::autoValidateAll()
847{
848 // Validate
849 ConfigurableElementListIterator it;
850
851 // Browse all configurable elements for configuration validation
852 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
853
854 const CConfigurableElement* pConfigurableElement = *it;
855
856 // Auto validate element
857 autoValidateAreas(pConfigurableElement);
858 }
859}
860
861// Attempt validation for configurable element's areas, relying on already existing valid configuration inside domain
862void CConfigurableDomain::autoValidateAreas(const CConfigurableElement* pConfigurableElement)
863{
864 // Find first valid configuration for given configurable element
865 const CDomainConfiguration* pValidDomainConfiguration = findValidDomainConfiguration(pConfigurableElement);
866
867 // No valid configuration found, give up
868 if (!pValidDomainConfiguration) {
869
870 return;
871 }
872
Patrick Benavoli68a91282011-08-31 11:23:23 +0200873 // Validate all other configurations against found one, if any
874 uint32_t uiNbConfigurations = getNbChildren();
875 uint32_t uiChild;
876
877 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
878
879 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
880
881 if (pDomainConfiguration != pValidDomainConfiguration && !pDomainConfiguration->isValid(pConfigurableElement)) {
882 // Validate
883 pDomainConfiguration->validateAgainst(pValidDomainConfiguration, pConfigurableElement);
884 }
885 }
886}
887
888// Attempt configuration validation for all configurable elements' areas, relying on already existing valid configuration inside domain
889bool CConfigurableDomain::autoValidateConfiguration(CDomainConfiguration* pDomainConfiguration)
890{
891 // Find another configuration than this one, that ought to be valid!
892 uint32_t uiNbConfigurations = getNbChildren();
893 uint32_t uiChild;
894
895 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
896
897 const CDomainConfiguration* pPotententialValidDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild));
898
899 if (pPotententialValidDomainConfiguration != pDomainConfiguration) {
900
901 // Validate against it
902 pDomainConfiguration->validateAgainst(pPotententialValidDomainConfiguration);
903
904 return true;
905 }
906 }
907 return false;
908}
Patrick Benavoli68a91282011-08-31 11:23:23 +0200909
Patrick Benavoli68a91282011-08-31 11:23:23 +0200910// Search for a valid configuration for given configurable element
911const CDomainConfiguration* CConfigurableDomain::findValidDomainConfiguration(const CConfigurableElement* pConfigurableElement) const
912{
913 uint32_t uiNbConfigurations = getNbChildren();
914 uint32_t uiChild;
915
916 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
917
918 const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild));
919
920 if (pDomainConfiguration->isValid(pConfigurableElement)) {
921
922 return pDomainConfiguration;
923 }
924 }
925 return NULL;
926}
927
928// Search for an applicable configuration
929const CDomainConfiguration* CConfigurableDomain::findApplicableDomainConfiguration() const
930{
931 uint32_t uiNbConfigurations = getNbChildren();
932 uint32_t uiChild;
933
934 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
935
936 const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild));
937
938 if (pDomainConfiguration->isApplicable()) {
939
940 return pDomainConfiguration;
941 }
942 }
943 return NULL;
944}
945
946// Gather set of configurable elements
947void CConfigurableDomain::gatherConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const
948{
949 // Insert all configurable elements
950 configurableElementSet.insert(_configurableElementList.begin(), _configurableElementList.end());
951}
952
953// Check configurable element already attached
954bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const
955{
956 ConfigurableElementListIterator it;
957
958 // Browse all configurable elements for comparison
959 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
960
961 if (pConfigurableCandidateElement == *it) {
962
963 return true;
964 }
965 }
966 return false;
967}
968
969// Merge any descended configurable element to this one with this one
970void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement)
971{
972 list<CConfigurableElement*> mergedConfigurableElementList;
973
974 ConfigurableElementListIterator it;
975
976 // Browse all configurable elements (new one not yet in the list!)
977 for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) {
978
979 CConfigurableElement* pConfigurablePotentialDescendantElement = *it;
980
981 if (pConfigurablePotentialDescendantElement->isDescendantOf(pNewConfigurableElement)) {
982
Kevin Rocardace81f82012-12-11 16:19:17 +0100983 log_info("In domain \"%s\", merging descendant configurable element's configurations \"%s\" into its ascendant \"%s\" ones", getName().c_str(), pConfigurablePotentialDescendantElement->getName().c_str(), pNewConfigurableElement->getName().c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200984
985 // Merge configuration data
986 mergeConfigurations(pNewConfigurableElement, pConfigurablePotentialDescendantElement);
987
988 // Keep track for removal
989 mergedConfigurableElementList.push_back(pConfigurablePotentialDescendantElement);
990 }
991 }
992
993 // Remove all merged elements (new one not yet in the list!)
994 for (it = mergedConfigurableElementList.begin(); it != mergedConfigurableElementList.end(); ++it) {
995
996 CConfigurableElement* pMergedConfigurableElement = *it;
997
998 // Remove merged from configurable element from internal tracking list
999 // Note: we shouldn't need to recompute the sync set in that case, as the merged to element should include the syncers of merged from elements
1000 doRemoveConfigurableElement(pMergedConfigurableElement, false);
1001 }
1002}
1003
1004void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement)
1005{
1006 // Propagate to domain configurations
1007 uint32_t uiNbConfigurations = getNbChildren();
1008 uint32_t uiChild;
1009
1010 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
1011
1012 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
1013
1014 // Do the merge.
1015 pDomainConfiguration->merge(pToConfigurableElement, pFromConfigurableElement);
1016 }
1017}
1018
1019// Configurable elements association
Frédéric Boisnard9620e442012-05-30 16:15:02 +02001020void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard *pMainBlackboard)
Patrick Benavoli68a91282011-08-31 11:23:23 +02001021{
1022 // Inform configurable element
1023 pConfigurableElement->addAttachedConfigurableDomain(this);
1024
Patrick Benavoli63499d42011-10-24 18:50:03 +02001025 // Create associated syncer set
1026 CSyncerSet* pSyncerSet = new CSyncerSet;
1027
1028 // Add to sync set the configurable element one
1029 pConfigurableElement->fillSyncerSet(*pSyncerSet);
1030
1031 // Store it
1032 _configurableElementToSyncerSetMap[pConfigurableElement] = pSyncerSet;
1033
1034 // Add it to global one
1035 _syncerSet += *pSyncerSet;
1036
Patrick Benavoli68a91282011-08-31 11:23:23 +02001037 // Inform configurations
1038 uint32_t uiNbConfigurations = getNbChildren();
1039 uint32_t uiChild;
1040
1041 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
1042
1043 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
1044
Patrick Benavoli63499d42011-10-24 18:50:03 +02001045 pDomainConfiguration->addConfigurableElement(pConfigurableElement, pSyncerSet);
Patrick Benavoli68a91282011-08-31 11:23:23 +02001046 }
Patrick Benavoli68a91282011-08-31 11:23:23 +02001047
Frédéric Boisnard9620e442012-05-30 16:15:02 +02001048 // Ensure area validity for that configurable element (if main blackboard provided)
1049 if (pMainBlackboard) {
1050
1051 // Need to validate against main blackboard
1052 validateAreas(pConfigurableElement, pMainBlackboard);
1053 }
1054
1055 // Already associated descendend configurable elements need a merge of their configuration data
Patrick Benavoli68a91282011-08-31 11:23:23 +02001056 mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement);
1057
1058 // Add to list
1059 _configurableElementList.push_back(pConfigurableElement);
1060}
1061
1062void CConfigurableDomain::doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet)
1063{
1064 // Remove from list
1065 _configurableElementList.remove(pConfigurableElement);
1066
Patrick Benavoli63499d42011-10-24 18:50:03 +02001067 // Remove associated syncer set
1068 CSyncerSet* pSyncerSet = getSyncerSet(pConfigurableElement);
1069
1070 _configurableElementToSyncerSetMap.erase(pConfigurableElement);
1071
1072 delete pSyncerSet;
1073
Patrick Benavoli68a91282011-08-31 11:23:23 +02001074 // Inform configurable element
1075 pConfigurableElement->removeAttachedConfigurableDomain(this);
1076
1077 // Inform configurations
1078 uint32_t uiNbConfigurations = getNbChildren();
1079 uint32_t uiChild;
1080
1081 for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) {
1082
1083 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild));
1084
1085 pDomainConfiguration->removeConfigurableElement(pConfigurableElement);
1086 }
1087 // Recompute our sync set if needed
1088 if (bRecomputeSyncSet) {
1089
1090 computeSyncSet();
1091 }
1092}
Patrick Benavoli63499d42011-10-24 18:50:03 +02001093
1094// Syncer set retrieval from configurable element
1095CSyncerSet* CConfigurableDomain::getSyncerSet(const CConfigurableElement* pConfigurableElement) const
1096{
1097 ConfigurableElementToSyncerSetMapIterator mapIt = _configurableElementToSyncerSetMap.find(pConfigurableElement);
1098
1099 assert(mapIt != _configurableElementToSyncerSetMap.end());
1100
1101 return mapIt->second;
1102}
Patrick Benavoli0bd50542011-11-29 11:10:27 +01001103
1104// Configuration retrieval
1105CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError)
1106{
1107 CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strConfiguration));
1108
1109 if (!pDomainConfiguration) {
1110
1111 strError = "Domain configuration " + strConfiguration + " not found";
1112
1113 return NULL;
1114 }
1115 return pDomainConfiguration;
1116}
1117
1118const CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) const
1119{
1120 const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration));
1121
1122 if (!pDomainConfiguration) {
1123
1124 strError = "Domain configuration " + strConfiguration + " not found";
1125
1126 return NULL;
1127 }
1128 return pDomainConfiguration;
1129}