| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 1 | /* |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 2 | * INTEL CONFIDENTIAL |
| 3 | * Copyright © 2011 Intel |
| 4 | * Corporation All Rights Reserved. |
| 5 | * |
| 6 | * The source code contained or described herein and all documents related to |
| 7 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 8 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 9 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 10 | * and confidential information of Intel or its suppliers and licensors. The |
| 11 | * Material is protected by worldwide copyright and trade secret laws and |
| 12 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 13 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 14 | * disclosed in any way without Intel’s prior express written permission. |
| 15 | * |
| 16 | * No license under any patent, copyright, trade secret or other intellectual |
| 17 | * property right is granted to or conferred upon you by disclosure or delivery |
| 18 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 19 | * otherwise. Any license under such intellectual property rights must be |
| 20 | * express and approved by Intel in writing. |
| 21 | * |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 22 | * CREATED: 2011-06-01 |
| 23 | * UPDATED: 2011-07-27 |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 24 | */ |
| 25 | #include "ConfigurableDomain.h" |
| 26 | #include "DomainConfiguration.h" |
| 27 | #include "ConfigurableElement.h" |
| 28 | #include "ConfigurationAccessContext.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 29 | #include "XmlDomainSerializingContext.h" |
| 30 | #include <assert.h> |
| 31 | |
| 32 | #define base CBinarySerializableElement |
| 33 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 34 | CConfigurableDomain::CConfigurableDomain(const string& strName) : base(strName), _bSequenceAware(false), _pLastAppliedConfiguration(NULL) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
| 38 | CConfigurableDomain::~CConfigurableDomain() |
| 39 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 40 | // Remove all configurable elements |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 41 | ConfigurableElementListIterator it; |
| 42 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 43 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 44 | |
| 45 | CConfigurableElement* pConfigurableElement = *it; |
| 46 | |
| 47 | // Remove from configurable element |
| 48 | pConfigurableElement->removeAttachedConfigurableDomain(this); |
| 49 | } |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 50 | |
| 51 | // Remove all associated syncer sets |
| 52 | ConfigurableElementToSyncerSetMapIterator mapIt; |
| 53 | |
| 54 | for (mapIt = _configurableElementToSyncerSetMap.begin(); mapIt != _configurableElementToSyncerSetMap.end(); ++mapIt) { |
| 55 | |
| 56 | delete mapIt->second; |
| 57 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | string CConfigurableDomain::getKind() const |
| 61 | { |
| 62 | return "ConfigurableDomain"; |
| 63 | } |
| 64 | |
| 65 | bool CConfigurableDomain::childrenAreDynamic() const |
| 66 | { |
| 67 | return true; |
| 68 | } |
| 69 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 70 | // Content dumping |
| 71 | void CConfigurableDomain::logValue(string& strValue, CErrorContext& errorContext) const |
| 72 | { |
| 73 | (void)errorContext; |
| 74 | |
| 75 | strValue = "{"; |
| 76 | |
| 77 | // Sequence awareness |
| 78 | strValue += "Sequence aware: "; |
| 79 | strValue += _bSequenceAware ? "yes" : "no"; |
| 80 | |
| 81 | // Last applied configuration |
| 82 | strValue += ", Last applied configuration: "; |
| 83 | strValue += _pLastAppliedConfiguration ? _pLastAppliedConfiguration->getName() : "<none>"; |
| 84 | |
| 85 | strValue += "}"; |
| 86 | } |
| 87 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 88 | // Sequence awareness |
| 89 | void CConfigurableDomain::setSequenceAwareness(bool bSequenceAware) |
| 90 | { |
| 91 | if (_bSequenceAware != bSequenceAware) { |
| 92 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 93 | log_info("Making domain \"%s\" sequence %s", getName().c_str(), bSequenceAware ? "aware" : "unaware"); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 94 | |
| 95 | _bSequenceAware = bSequenceAware; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | bool CConfigurableDomain::getSequenceAwareness() const |
| 100 | { |
| 101 | return _bSequenceAware; |
| 102 | } |
| 103 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 104 | // From IXmlSource |
| 105 | void CConfigurableDomain::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const |
| 106 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 107 | // Sequence awareness |
| 108 | xmlElement.setAttributeBoolean("SequenceAware", _bSequenceAware); |
| 109 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 110 | // Configurations |
| 111 | composeDomainConfigurations(xmlElement, serializingContext); |
| 112 | |
| 113 | // Configurable Elements |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 114 | composeConfigurableElements(xmlElement); |
| 115 | |
| 116 | // Settings |
| 117 | composeSettings(xmlElement, serializingContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // XML composing |
| 121 | void CConfigurableDomain::composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const |
| 122 | { |
| 123 | // Create Configurations element |
| 124 | CXmlElement xmlConfigurationsElement; |
| 125 | |
| 126 | xmlElement.createChild(xmlConfigurationsElement, "Configurations"); |
| 127 | |
| 128 | // Delegate to base |
| 129 | base::toXml(xmlConfigurationsElement, serializingContext); |
| 130 | } |
| 131 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 132 | void CConfigurableDomain::composeConfigurableElements(CXmlElement& xmlElement) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 133 | { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 134 | // Create ConfigurableElements element |
| 135 | CXmlElement xmlConfigurableElementsElement; |
| 136 | |
| 137 | xmlElement.createChild(xmlConfigurableElementsElement, "ConfigurableElements"); |
| 138 | |
| 139 | // Serialize out all configurable elements settings |
| 140 | ConfigurableElementListIterator it; |
| 141 | |
| 142 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 143 | |
| 144 | const CConfigurableElement* pConfigurableElement = *it; |
| 145 | |
| 146 | // Create corresponding XML child element |
| 147 | CXmlElement xmlChildConfigurableElement; |
| 148 | |
| 149 | xmlConfigurableElementsElement.createChild(xmlChildConfigurableElement, "ConfigurableElement"); |
| 150 | |
| 151 | // Set Path attribute |
| 152 | xmlChildConfigurableElement.setAttributeString("Path", pConfigurableElement->getPath()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 156 | void CConfigurableDomain::composeSettings(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 157 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 158 | // Context |
| 159 | const CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<const CXmlDomainSerializingContext&>(serializingContext); |
| 160 | |
| 161 | if (!xmlDomainSerializingContext.withSettings()) { |
| 162 | |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | // Create Settings element |
| 167 | CXmlElement xmlSettingsElement; |
| 168 | |
| 169 | xmlElement.createChild(xmlSettingsElement, "Settings"); |
| 170 | |
| 171 | // Serialize out all configurations settings |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 172 | uint32_t uiNbConfigurations = getNbChildren(); |
| 173 | uint32_t uiChildConfiguration; |
| 174 | |
| 175 | for (uiChildConfiguration = 0; uiChildConfiguration < uiNbConfigurations; uiChildConfiguration++) { |
| 176 | |
| 177 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChildConfiguration)); |
| 178 | |
| 179 | // Create child xml element for that configuration |
| 180 | CXmlElement xmlConfigurationSettingsElement; |
| 181 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 182 | xmlSettingsElement.createChild(xmlConfigurationSettingsElement, pDomainConfiguration->getKind()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 183 | |
| 184 | // Set its name attribute |
| 185 | xmlConfigurationSettingsElement.setNameAttribute(pDomainConfiguration->getName()); |
| 186 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 187 | // Serialize out configuration settings |
| 188 | pDomainConfiguration->composeSettings(xmlConfigurationSettingsElement, serializingContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
| 192 | // From IXmlSink |
| 193 | bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) |
| 194 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 195 | // Context |
| 196 | CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<CXmlDomainSerializingContext&>(serializingContext); |
| 197 | |
| 198 | // Sequence awareness (optional) |
| 199 | _bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware"); |
| 200 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 201 | // Local parsing. Do not dig |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 202 | if (!parseDomainConfigurations(xmlElement, serializingContext) || !parseConfigurableElements(xmlElement, serializingContext) || !parseSettings(xmlElement, serializingContext)) { |
| 203 | |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | // All provided configurations are parsed |
| 208 | // Attempt validation on areas of non provided configurations for all configurable elements if required |
| 209 | if (xmlDomainSerializingContext.autoValidationRequired()) { |
| 210 | |
| 211 | autoValidateAll(); |
| 212 | } |
| 213 | |
| 214 | return true; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // XML parsing |
| 218 | bool CConfigurableDomain::parseDomainConfigurations(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) |
| 219 | { |
| 220 | // We're supposedly clean |
| 221 | assert(_configurableElementList.empty()); |
| 222 | |
| 223 | // Get Configurations element |
| 224 | CXmlElement xmlConfigurationsElement; |
| 225 | |
| 226 | xmlElement.getChildElement("Configurations", xmlConfigurationsElement); |
| 227 | |
| 228 | // Parse it and create domain configuration objects |
| 229 | return base::fromXml(xmlConfigurationsElement, serializingContext); |
| 230 | } |
| 231 | |
| 232 | // Parse configurable elements |
| 233 | bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) |
| 234 | { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 235 | // Get System Class Element |
| 236 | CElement* pRootElement = getRoot(); |
| 237 | |
| 238 | CElement* pSystemClassElement = pRootElement->findChildOfKind("SystemClass"); |
| 239 | |
| 240 | assert(pSystemClassElement); |
| 241 | |
| 242 | // Get ConfigurableElements element |
| 243 | CXmlElement xmlConfigurableElementsElement; |
| 244 | xmlElement.getChildElement("ConfigurableElements", xmlConfigurableElementsElement); |
| 245 | |
| 246 | // Parse it and associate found configurable elements to it |
| 247 | CXmlElement::CChildIterator it(xmlConfigurableElementsElement); |
| 248 | |
| 249 | CXmlElement xmlConfigurableElementElement; |
| 250 | |
| 251 | while (it.next(xmlConfigurableElementElement)) { |
| 252 | |
| 253 | // Locate configurable element |
| 254 | string strConfigurableElementPath = xmlConfigurableElementElement.getAttributeString("Path"); |
| 255 | |
| 256 | CPathNavigator pathNavigator(strConfigurableElementPath); |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 257 | string strError; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 258 | |
| 259 | // Is there an element and does it match system class name? |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 260 | if (!pathNavigator.navigateThrough(pSystemClassElement->getName(), strError)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 261 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 262 | serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName() + " (" + strError + ")"); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 263 | |
| 264 | return false; |
| 265 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 266 | // Browse system class for configurable element |
| 267 | CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pSystemClassElement->findDescendant(pathNavigator)); |
| 268 | |
| 269 | if (!pConfigurableElement) { |
| 270 | |
| 271 | serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName()); |
| 272 | |
| 273 | return false; |
| 274 | } |
| 275 | // Add found element to domain |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 276 | if (!addConfigurableElement(pConfigurableElement, NULL, strError)) { |
| 277 | |
| 278 | serializingContext.setError(strError); |
| 279 | |
| 280 | return false; |
| 281 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 282 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 283 | |
| 284 | return true; |
| 285 | } |
| 286 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 287 | // Parse settings |
| 288 | bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 289 | { |
| 290 | // Context |
| 291 | CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<CXmlDomainSerializingContext&>(serializingContext); |
| 292 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 293 | // Check we actually need to parse configuration settings |
| 294 | if (!xmlDomainSerializingContext.withSettings()) { |
| 295 | |
| 296 | // No parsing required |
| 297 | return true; |
| 298 | } |
| 299 | |
| 300 | // Get Settings element |
| 301 | CXmlElement xmlSettingsElement; |
| 302 | if (!xmlElement.getChildElement("Settings", xmlSettingsElement)) { |
| 303 | |
| 304 | // No settings, bail out successfully |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | // Parse configuration settings |
| 309 | CXmlElement::CChildIterator it(xmlSettingsElement); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 310 | |
| 311 | CXmlElement xmlConfigurationSettingsElement; |
| 312 | |
| 313 | while (it.next(xmlConfigurationSettingsElement)) { |
| 314 | // Get domain configuration |
| 315 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(xmlConfigurationSettingsElement.getNameAttribute())); |
| 316 | |
| 317 | if (!pDomainConfiguration) { |
| 318 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 319 | xmlDomainSerializingContext.setError("Could not find domain configuration referred to by configurable domain " + getName()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 320 | |
| 321 | return false; |
| 322 | } |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 323 | // Have domain configuration parse settings for all configurable elements |
| 324 | if (!pDomainConfiguration->parseSettings(xmlConfigurationSettingsElement, xmlDomainSerializingContext)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 325 | |
| 326 | return false; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | return true; |
| 331 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 332 | // Configurable elements association |
| 333 | bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 334 | { |
| 335 | // Already associated? |
| 336 | if (containsConfigurableElement(pConfigurableElement)) { |
| 337 | |
| 338 | strError = "Configurable element " + pConfigurableElement->getPath() + " already associated to configuration domain " + getName(); |
| 339 | |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | // Already owned? |
| 344 | if (pConfigurableElement->belongsTo(this)) { |
| 345 | |
| 346 | strError = "Configurable element " + pConfigurableElement->getPath() + " already owned by configuration domain " + getName(); |
| 347 | |
| 348 | return false; |
| 349 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 350 | |
| 351 | // Do add |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 352 | doAddConfigurableElement(pConfigurableElement, pMainBlackboard); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 353 | |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | bool CConfigurableDomain::removeConfigurableElement(CConfigurableElement* pConfigurableElement, string& strError) |
| 358 | { |
| 359 | // Not associated? |
| 360 | if (!containsConfigurableElement(pConfigurableElement)) { |
| 361 | |
| 362 | strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName(); |
| 363 | |
| 364 | return false; |
| 365 | } |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 366 | log_info("Removing configurable element \"%s\" from domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 367 | |
| 368 | // Do remove |
| 369 | doRemoveConfigurableElement(pConfigurableElement, true); |
| 370 | |
| 371 | return true; |
| 372 | } |
| 373 | |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 374 | /** |
| 375 | * Blackboard Configuration and Base Offset retrieval. |
| 376 | * |
| 377 | * This method fetches the Blackboard associated to the ConfigurableElement |
| 378 | * given in parameter, for a specific Configuration. The ConfigurableElement |
| 379 | * must belong to the Domain. If a Blackboard is found, the base offset of |
| 380 | * the ConfigurableElement is returned as well. This base offset corresponds to |
| 381 | * the offset of the ancestor of the ConfigurableElement associated to the Configuration. |
| 382 | * |
| 383 | * @param[in] strConfiguration Name of the Configuration. |
| 384 | * @param[in] pCandidateDescendantConfigurableElement Pointer to a CConfigurableElement that |
| 385 | * belongs to the Domain. |
| 386 | * @param[out] uiBaseOffset The base offset of the CConfigurableElement. |
| 387 | * @param[out] bIsLastApplied Boolean indicating that the Configuration is |
| 388 | * the last one applied of the Domain. |
| 389 | * @param[out] strError Error message |
| 390 | * |
| 391 | * return Pointer to the Blackboard of the Configuration. |
| 392 | */ |
| 393 | CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const string& strConfiguration, |
| 394 | const CConfigurableElement* pCandidateDescendantConfigurableElement, |
| 395 | uint32_t& uiBaseOffset, |
| 396 | bool& bIsLastApplied, |
| 397 | string& strError) const |
| 398 | { |
| 399 | // Find Configuration |
| 400 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration)); |
| 401 | |
| 402 | if (!pDomainConfiguration) { |
| 403 | |
| 404 | strError = "Domain configuration " + strConfiguration + " not found"; |
| 405 | |
| 406 | return NULL; |
| 407 | } |
| 408 | |
| 409 | // Parse all configurable elements |
| 410 | ConfigurableElementListIterator it; |
| 411 | |
| 412 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 413 | |
| 414 | const CConfigurableElement* pAssociatedConfigurableElement = *it; |
| 415 | |
| 416 | // Check if the the associated element is the configurable element or one of its ancestors |
| 417 | if ((pCandidateDescendantConfigurableElement == pAssociatedConfigurableElement) || |
| 418 | (pCandidateDescendantConfigurableElement->isDescendantOf(pAssociatedConfigurableElement))) { |
| 419 | |
| 420 | uiBaseOffset = pAssociatedConfigurableElement->getOffset(); |
| 421 | bIsLastApplied = (pDomainConfiguration == _pLastAppliedConfiguration); |
| 422 | |
| 423 | return pDomainConfiguration->getBlackboard(pAssociatedConfigurableElement); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | strError = "Element not associated to the Domain"; |
| 428 | |
| 429 | return NULL; |
| 430 | } |
| 431 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 432 | // Domain splitting |
| 433 | bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, string& strError) |
| 434 | { |
| 435 | // Not associated? |
| 436 | if (!containsConfigurableElement(pConfigurableElement)) { |
| 437 | |
| 438 | strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName(); |
| 439 | |
| 440 | return false; |
| 441 | } |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 442 | log_info("Splitting configurable element \"%s\" domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 443 | |
| 444 | // Create sub domain areas for all configurable element's children |
| 445 | uint32_t uiNbConfigurableElementChildren = pConfigurableElement->getNbChildren(); |
| 446 | |
| 447 | if (!uiNbConfigurableElementChildren) { |
| 448 | |
| 449 | strError = "Configurable element " + pConfigurableElement->getPath() + " has no children to split configurable domain to"; |
| 450 | |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | uint32_t uiChild; |
| 455 | |
| 456 | for (uiChild = 0; uiChild < uiNbConfigurableElementChildren; uiChild++) { |
| 457 | |
| 458 | CConfigurableElement* pChildConfigurableElement = static_cast<CConfigurableElement*>(pConfigurableElement->getChild(uiChild)); |
| 459 | |
| 460 | doAddConfigurableElement(pChildConfigurableElement); |
| 461 | } |
| 462 | |
| 463 | // Delegate to configurations |
| 464 | uint32_t uiNbConfigurations = getNbChildren(); |
| 465 | |
| 466 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 467 | |
| 468 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 469 | |
| 470 | pDomainConfiguration->split(pConfigurableElement); |
| 471 | } |
| 472 | |
| 473 | // Remove given configurable element from this domain |
| 474 | // 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 |
| 475 | doRemoveConfigurableElement(pConfigurableElement, false); |
| 476 | |
| 477 | return true; |
| 478 | } |
| 479 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 480 | // Check if there is a pending configuration for this domain: i.e. an applicable configuration different from the last applied configuration |
| 481 | const CDomainConfiguration* CConfigurableDomain::getPendingConfiguration() const |
| 482 | { |
| 483 | const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration(); |
| 484 | |
| 485 | if (pApplicableDomainConfiguration) { |
| 486 | |
| 487 | // Check not the last one before applying |
| 488 | if (!_pLastAppliedConfiguration || (_pLastAppliedConfiguration != pApplicableDomainConfiguration)) { |
| 489 | |
| 490 | return pApplicableDomainConfiguration; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | return NULL; |
| 495 | } |
| 496 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 497 | // Configuration application if required |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 498 | void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForce) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 499 | { |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 500 | // Apply configuration only if the blackboard will |
| 501 | // be synchronized either now or by syncerSet. |
| 502 | if(!pSyncerSet ^ _bSequenceAware) { |
| 503 | // The configuration can not be syncronised |
| 504 | return; |
| 505 | } |
| 506 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 507 | if (bForce) { |
| 508 | // Force a configuration restore by forgetting about last applied configuration |
| 509 | _pLastAppliedConfiguration = NULL; |
| 510 | } |
| 511 | const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration(); |
| 512 | |
| 513 | if (pApplicableDomainConfiguration) { |
| 514 | |
| 515 | // Check not the last one before applying |
| 516 | if (!_pLastAppliedConfiguration || _pLastAppliedConfiguration != pApplicableDomainConfiguration) { |
| 517 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 518 | log_info("Applying configuration \"%s\" from domain \"%s\"", |
| 519 | pApplicableDomainConfiguration->getName().c_str(), |
| 520 | getName().c_str()); |
| 521 | |
| 522 | // Check if we need to synchronize during restore |
| 523 | bool bSync = !pSyncerSet && _bSequenceAware; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 524 | |
| 525 | // Do the restore |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 526 | pApplicableDomainConfiguration->restore(pParameterBlackboard, bSync, NULL); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 527 | |
| 528 | // Record last applied configuration |
| 529 | _pLastAppliedConfiguration = pApplicableDomainConfiguration; |
| 530 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 531 | // Check we need to provide syncer set to caller |
| 532 | if (pSyncerSet && !_bSequenceAware) { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 533 | |
| 534 | // Since we applied changes, add our own sync set to the given one |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 535 | *pSyncerSet += _syncerSet; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 536 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | // Return applicable configuration validity for given configurable element |
| 542 | bool CConfigurableDomain::isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const |
| 543 | { |
| 544 | const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration(); |
| 545 | |
| 546 | return pApplicableDomainConfiguration && pApplicableDomainConfiguration->isValid(pConfigurableElement); |
| 547 | } |
| 548 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 549 | // In case configurable element was removed |
| 550 | void CConfigurableDomain::computeSyncSet() |
| 551 | { |
| 552 | // Clean sync set first |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 553 | _syncerSet.clear(); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 554 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 555 | // Add syncer sets for all associated configurable elements |
| 556 | ConfigurableElementToSyncerSetMapIterator mapIt; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 557 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 558 | for (mapIt = _configurableElementToSyncerSetMap.begin(); mapIt != _configurableElementToSyncerSetMap.end(); ++mapIt) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 559 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 560 | const CSyncerSet* pSyncerSet = mapIt->second; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 561 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 562 | _syncerSet += *pSyncerSet; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
| 566 | // Configuration Management |
| 567 | bool CConfigurableDomain::createConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 568 | { |
| 569 | // Already exists? |
| 570 | if (findChild(strName)) { |
| 571 | |
| 572 | strError = "Already existing configuration"; |
| 573 | |
| 574 | return false; |
| 575 | } |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 576 | log_info("Creating domain configuration \"%s\" into domain \"%s\"", strName.c_str(), getName().c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 577 | |
| 578 | // Creation |
| 579 | CDomainConfiguration* pDomainConfiguration = new CDomainConfiguration(strName); |
| 580 | |
| 581 | // Configurable elements association |
| 582 | ConfigurableElementListIterator it; |
| 583 | |
| 584 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 585 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 586 | const CConfigurableElement* pConfigurableElement = *it;; |
| 587 | |
| 588 | // Retrieve associated syncer set |
| 589 | CSyncerSet* pSyncerSet = getSyncerSet(pConfigurableElement); |
| 590 | |
| 591 | // Associate to configuration |
| 592 | pDomainConfiguration->addConfigurableElement(pConfigurableElement, pSyncerSet); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | // Hierarchy |
| 596 | addChild(pDomainConfiguration); |
| 597 | |
| 598 | // Ensure validity of fresh new domain configuration |
| 599 | // Attempt auto validation, so that the user gets his/her own settings by defaults |
| 600 | if (!autoValidateConfiguration(pDomainConfiguration)) { |
| 601 | |
| 602 | // No valid configuration found to copy in from, validate againt main blackboard (will concerned remaining invalid parts) |
| 603 | pDomainConfiguration->validate(pMainBlackboard); |
| 604 | } |
| 605 | |
| 606 | return true; |
| 607 | } |
| 608 | |
| 609 | bool CConfigurableDomain::deleteConfiguration(const string& strName, string& strError) |
| 610 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 611 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 612 | |
| 613 | if (!pDomainConfiguration) { |
| 614 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 615 | return false; |
| 616 | } |
| 617 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 618 | log_info("Deleting configuration \"%s\" from domain \"%s\"", strName.c_str(), getName().c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 619 | |
| 620 | // Was the last applied? |
| 621 | if (pDomainConfiguration == _pLastAppliedConfiguration) { |
| 622 | |
| 623 | // Forget about it |
| 624 | _pLastAppliedConfiguration = NULL; |
| 625 | } |
| 626 | |
| 627 | // Hierarchy |
| 628 | removeChild(pDomainConfiguration); |
| 629 | |
| 630 | // Destroy |
| 631 | delete pDomainConfiguration; |
| 632 | |
| 633 | return true; |
| 634 | } |
| 635 | |
| 636 | void CConfigurableDomain::listAssociatedToElements(string& strResult) const |
| 637 | { |
| 638 | strResult = "\n"; |
| 639 | |
| 640 | ConfigurableElementListIterator it; |
| 641 | |
| 642 | // Browse all configurable elements |
| 643 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 644 | |
| 645 | const CConfigurableElement* pConfigurableElement = *it; |
| 646 | |
| 647 | strResult += pConfigurableElement->getPath() + "\n"; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | bool CConfigurableDomain::renameConfiguration(const string& strName, const string& strNewName, string& strError) |
| 652 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 653 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 654 | |
| 655 | if (!pDomainConfiguration) { |
| 656 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 657 | return false; |
| 658 | } |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 659 | log_info("Renaming domain \"%s\"'s configuration \"%s\" to \"%s\"", getName().c_str(), strName.c_str(), strNewName.c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 660 | |
| 661 | // Rename |
| 662 | return pDomainConfiguration->rename(strNewName, strError); |
| 663 | } |
| 664 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 665 | bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, list<string>& lstrError) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 666 | { |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 667 | string strError; |
| 668 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 669 | const CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 670 | |
| 671 | if (!pDomainConfiguration) { |
| 672 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 673 | lstrError.push_back(strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 674 | return false; |
| 675 | } |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 676 | log_info("Restoring domain \"%s\"'s configuration \"%s\" to parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 677 | |
| 678 | // Delegate |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 679 | bool bSuccess = pDomainConfiguration->restore(pMainBlackboard, bAutoSync && _bSequenceAware, &lstrError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 680 | |
| 681 | // Record last applied configuration |
| 682 | _pLastAppliedConfiguration = pDomainConfiguration; |
| 683 | |
| 684 | // Synchronize |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 685 | if (bAutoSync && !_bSequenceAware) { |
| 686 | |
| 687 | bSuccess &= _syncerSet.sync(*pMainBlackboard, false, &lstrError); |
| 688 | } |
| 689 | return bSuccess; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | bool CConfigurableDomain::saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 693 | { |
| 694 | // Find Domain configuration |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 695 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 696 | |
| 697 | if (!pDomainConfiguration) { |
| 698 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 699 | return false; |
| 700 | } |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 701 | log_info("Saving domain \"%s\"'s configuration \"%s\" from parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 702 | |
| 703 | // Delegate |
| 704 | pDomainConfiguration->save(pMainBlackboard); |
| 705 | |
| 706 | return true; |
| 707 | } |
| 708 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 709 | bool CConfigurableDomain::setElementSequence(const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError) |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 710 | { |
| 711 | // Find Domain configuration |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 712 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 713 | |
| 714 | if (!pDomainConfiguration) { |
| 715 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 716 | return false; |
| 717 | } |
| 718 | |
| 719 | // Delegate to configuration |
| 720 | return pDomainConfiguration->setElementSequence(astrNewElementSequence, strError); |
| 721 | } |
| 722 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 723 | bool CConfigurableDomain::getElementSequence(const string& strConfiguration, string& strResult) const |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 724 | { |
| 725 | // Find Domain configuration |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 726 | const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 727 | |
| 728 | if (!pDomainConfiguration) { |
| 729 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 730 | return false; |
| 731 | } |
| 732 | |
| 733 | // Delegate to configuration |
| 734 | pDomainConfiguration->getElementSequence(strResult); |
| 735 | |
| 736 | return true; |
| 737 | } |
| 738 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 739 | bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) |
| 740 | { |
| 741 | // Find Domain configuration |
| 742 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); |
| 743 | |
| 744 | if (!pDomainConfiguration) { |
| 745 | |
| 746 | return false; |
| 747 | } |
| 748 | |
| 749 | // Delegate to configuration |
| 750 | return pDomainConfiguration->setApplicationRule(strApplicationRule, pSelectionCriteriaDefinition, strError); |
| 751 | } |
| 752 | |
| 753 | bool CConfigurableDomain::clearApplicationRule(const string& strConfiguration, string& strError) |
| 754 | { |
| 755 | // Find Domain configuration |
| 756 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); |
| 757 | |
| 758 | if (!pDomainConfiguration) { |
| 759 | |
| 760 | return false; |
| 761 | } |
| 762 | |
| 763 | // Delegate to configuration |
| 764 | pDomainConfiguration->clearApplicationRule(); |
| 765 | |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | bool CConfigurableDomain::getApplicationRule(const string& strConfiguration, string& strResult) const |
| 770 | { |
| 771 | // Find Domain configuration |
| 772 | const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult); |
| 773 | |
| 774 | if (!pDomainConfiguration) { |
| 775 | |
| 776 | return false; |
| 777 | } |
| 778 | |
| 779 | // Delegate to configuration |
| 780 | pDomainConfiguration->getApplicationRule(strResult); |
| 781 | |
| 782 | return true; |
| 783 | } |
| 784 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 785 | // Last applied configuration |
| 786 | string CConfigurableDomain::getLastAppliedConfigurationName() const |
| 787 | { |
| 788 | if (_pLastAppliedConfiguration) { |
| 789 | |
| 790 | return _pLastAppliedConfiguration->getName(); |
| 791 | } |
| 792 | return "<none>"; |
| 793 | } |
| 794 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 795 | // Pending configuration |
| 796 | string CConfigurableDomain::getPendingConfigurationName() const |
| 797 | { |
| 798 | const CDomainConfiguration* pPendingConfiguration = getPendingConfiguration(); |
| 799 | |
| 800 | if (pPendingConfiguration) { |
| 801 | |
| 802 | return pPendingConfiguration->getName(); |
| 803 | } |
| 804 | return "<none>"; |
| 805 | } |
| 806 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 807 | // Ensure validity on whole domain from main blackboard |
| 808 | void CConfigurableDomain::validate(const CParameterBlackboard* pMainBlackboard) |
| 809 | { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 810 | |
| 811 | // Propagate |
| 812 | uint32_t uiNbConfigurations = getNbChildren(); |
| 813 | uint32_t uiChild; |
| 814 | |
| 815 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 816 | |
| 817 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 818 | |
| 819 | pDomainConfiguration->validate(pMainBlackboard); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | // Ensure validity on areas related to configurable element |
| 824 | void CConfigurableDomain::validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) |
| 825 | { |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 826 | log_info("Validating domain \"" + getName() + "\" against main blackboard for configurable element \"" + pConfigurableElement->getPath() + "\""); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 827 | |
| 828 | // Propagate |
| 829 | uint32_t uiNbConfigurations = getNbChildren(); |
| 830 | uint32_t uiChild; |
| 831 | |
| 832 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 833 | |
| 834 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 835 | |
| 836 | pDomainConfiguration->validate(pConfigurableElement, pMainBlackboard); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | // Attempt validation for all configurable element's areas, relying on already existing valid configuration inside domain |
| 841 | void CConfigurableDomain::autoValidateAll() |
| 842 | { |
| 843 | // Validate |
| 844 | ConfigurableElementListIterator it; |
| 845 | |
| 846 | // Browse all configurable elements for configuration validation |
| 847 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 848 | |
| 849 | const CConfigurableElement* pConfigurableElement = *it; |
| 850 | |
| 851 | // Auto validate element |
| 852 | autoValidateAreas(pConfigurableElement); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | // Attempt validation for configurable element's areas, relying on already existing valid configuration inside domain |
| 857 | void CConfigurableDomain::autoValidateAreas(const CConfigurableElement* pConfigurableElement) |
| 858 | { |
| 859 | // Find first valid configuration for given configurable element |
| 860 | const CDomainConfiguration* pValidDomainConfiguration = findValidDomainConfiguration(pConfigurableElement); |
| 861 | |
| 862 | // No valid configuration found, give up |
| 863 | if (!pValidDomainConfiguration) { |
| 864 | |
| 865 | return; |
| 866 | } |
| 867 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 868 | // Validate all other configurations against found one, if any |
| 869 | uint32_t uiNbConfigurations = getNbChildren(); |
| 870 | uint32_t uiChild; |
| 871 | |
| 872 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 873 | |
| 874 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 875 | |
| 876 | if (pDomainConfiguration != pValidDomainConfiguration && !pDomainConfiguration->isValid(pConfigurableElement)) { |
| 877 | // Validate |
| 878 | pDomainConfiguration->validateAgainst(pValidDomainConfiguration, pConfigurableElement); |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | // Attempt configuration validation for all configurable elements' areas, relying on already existing valid configuration inside domain |
| 884 | bool CConfigurableDomain::autoValidateConfiguration(CDomainConfiguration* pDomainConfiguration) |
| 885 | { |
| 886 | // Find another configuration than this one, that ought to be valid! |
| 887 | uint32_t uiNbConfigurations = getNbChildren(); |
| 888 | uint32_t uiChild; |
| 889 | |
| 890 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 891 | |
| 892 | const CDomainConfiguration* pPotententialValidDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); |
| 893 | |
| 894 | if (pPotententialValidDomainConfiguration != pDomainConfiguration) { |
| 895 | |
| 896 | // Validate against it |
| 897 | pDomainConfiguration->validateAgainst(pPotententialValidDomainConfiguration); |
| 898 | |
| 899 | return true; |
| 900 | } |
| 901 | } |
| 902 | return false; |
| 903 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 904 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 905 | // Search for a valid configuration for given configurable element |
| 906 | const CDomainConfiguration* CConfigurableDomain::findValidDomainConfiguration(const CConfigurableElement* pConfigurableElement) const |
| 907 | { |
| 908 | uint32_t uiNbConfigurations = getNbChildren(); |
| 909 | uint32_t uiChild; |
| 910 | |
| 911 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 912 | |
| 913 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); |
| 914 | |
| 915 | if (pDomainConfiguration->isValid(pConfigurableElement)) { |
| 916 | |
| 917 | return pDomainConfiguration; |
| 918 | } |
| 919 | } |
| 920 | return NULL; |
| 921 | } |
| 922 | |
| 923 | // Search for an applicable configuration |
| 924 | const CDomainConfiguration* CConfigurableDomain::findApplicableDomainConfiguration() const |
| 925 | { |
| 926 | uint32_t uiNbConfigurations = getNbChildren(); |
| 927 | uint32_t uiChild; |
| 928 | |
| 929 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 930 | |
| 931 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); |
| 932 | |
| 933 | if (pDomainConfiguration->isApplicable()) { |
| 934 | |
| 935 | return pDomainConfiguration; |
| 936 | } |
| 937 | } |
| 938 | return NULL; |
| 939 | } |
| 940 | |
| 941 | // Gather set of configurable elements |
| 942 | void CConfigurableDomain::gatherConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const |
| 943 | { |
| 944 | // Insert all configurable elements |
| 945 | configurableElementSet.insert(_configurableElementList.begin(), _configurableElementList.end()); |
| 946 | } |
| 947 | |
| 948 | // Check configurable element already attached |
| 949 | bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const |
| 950 | { |
| 951 | ConfigurableElementListIterator it; |
| 952 | |
| 953 | // Browse all configurable elements for comparison |
| 954 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 955 | |
| 956 | if (pConfigurableCandidateElement == *it) { |
| 957 | |
| 958 | return true; |
| 959 | } |
| 960 | } |
| 961 | return false; |
| 962 | } |
| 963 | |
| 964 | // Merge any descended configurable element to this one with this one |
| 965 | void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement) |
| 966 | { |
| 967 | list<CConfigurableElement*> mergedConfigurableElementList; |
| 968 | |
| 969 | ConfigurableElementListIterator it; |
| 970 | |
| 971 | // Browse all configurable elements (new one not yet in the list!) |
| 972 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 973 | |
| 974 | CConfigurableElement* pConfigurablePotentialDescendantElement = *it; |
| 975 | |
| 976 | if (pConfigurablePotentialDescendantElement->isDescendantOf(pNewConfigurableElement)) { |
| 977 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 978 | 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 979 | |
| 980 | // Merge configuration data |
| 981 | mergeConfigurations(pNewConfigurableElement, pConfigurablePotentialDescendantElement); |
| 982 | |
| 983 | // Keep track for removal |
| 984 | mergedConfigurableElementList.push_back(pConfigurablePotentialDescendantElement); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | // Remove all merged elements (new one not yet in the list!) |
| 989 | for (it = mergedConfigurableElementList.begin(); it != mergedConfigurableElementList.end(); ++it) { |
| 990 | |
| 991 | CConfigurableElement* pMergedConfigurableElement = *it; |
| 992 | |
| 993 | // Remove merged from configurable element from internal tracking list |
| 994 | // 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 |
| 995 | doRemoveConfigurableElement(pMergedConfigurableElement, false); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement) |
| 1000 | { |
| 1001 | // Propagate to domain configurations |
| 1002 | uint32_t uiNbConfigurations = getNbChildren(); |
| 1003 | uint32_t uiChild; |
| 1004 | |
| 1005 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 1006 | |
| 1007 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 1008 | |
| 1009 | // Do the merge. |
| 1010 | pDomainConfiguration->merge(pToConfigurableElement, pFromConfigurableElement); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | // Configurable elements association |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 1015 | void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard *pMainBlackboard) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1016 | { |
| 1017 | // Inform configurable element |
| 1018 | pConfigurableElement->addAttachedConfigurableDomain(this); |
| 1019 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1020 | // Create associated syncer set |
| 1021 | CSyncerSet* pSyncerSet = new CSyncerSet; |
| 1022 | |
| 1023 | // Add to sync set the configurable element one |
| 1024 | pConfigurableElement->fillSyncerSet(*pSyncerSet); |
| 1025 | |
| 1026 | // Store it |
| 1027 | _configurableElementToSyncerSetMap[pConfigurableElement] = pSyncerSet; |
| 1028 | |
| 1029 | // Add it to global one |
| 1030 | _syncerSet += *pSyncerSet; |
| 1031 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1032 | // Inform configurations |
| 1033 | uint32_t uiNbConfigurations = getNbChildren(); |
| 1034 | uint32_t uiChild; |
| 1035 | |
| 1036 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 1037 | |
| 1038 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 1039 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1040 | pDomainConfiguration->addConfigurableElement(pConfigurableElement, pSyncerSet); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1041 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1042 | |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 1043 | // Ensure area validity for that configurable element (if main blackboard provided) |
| 1044 | if (pMainBlackboard) { |
| 1045 | |
| 1046 | // Need to validate against main blackboard |
| 1047 | validateAreas(pConfigurableElement, pMainBlackboard); |
| 1048 | } |
| 1049 | |
| 1050 | // Already associated descendend configurable elements need a merge of their configuration data |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1051 | mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement); |
| 1052 | |
| 1053 | // Add to list |
| 1054 | _configurableElementList.push_back(pConfigurableElement); |
| 1055 | } |
| 1056 | |
| 1057 | void CConfigurableDomain::doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet) |
| 1058 | { |
| 1059 | // Remove from list |
| 1060 | _configurableElementList.remove(pConfigurableElement); |
| 1061 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1062 | // Remove associated syncer set |
| 1063 | CSyncerSet* pSyncerSet = getSyncerSet(pConfigurableElement); |
| 1064 | |
| 1065 | _configurableElementToSyncerSetMap.erase(pConfigurableElement); |
| 1066 | |
| 1067 | delete pSyncerSet; |
| 1068 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1069 | // Inform configurable element |
| 1070 | pConfigurableElement->removeAttachedConfigurableDomain(this); |
| 1071 | |
| 1072 | // Inform configurations |
| 1073 | uint32_t uiNbConfigurations = getNbChildren(); |
| 1074 | uint32_t uiChild; |
| 1075 | |
| 1076 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 1077 | |
| 1078 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 1079 | |
| 1080 | pDomainConfiguration->removeConfigurableElement(pConfigurableElement); |
| 1081 | } |
| 1082 | // Recompute our sync set if needed |
| 1083 | if (bRecomputeSyncSet) { |
| 1084 | |
| 1085 | computeSyncSet(); |
| 1086 | } |
| 1087 | } |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1088 | |
| 1089 | // Syncer set retrieval from configurable element |
| 1090 | CSyncerSet* CConfigurableDomain::getSyncerSet(const CConfigurableElement* pConfigurableElement) const |
| 1091 | { |
| 1092 | ConfigurableElementToSyncerSetMapIterator mapIt = _configurableElementToSyncerSetMap.find(pConfigurableElement); |
| 1093 | |
| 1094 | assert(mapIt != _configurableElementToSyncerSetMap.end()); |
| 1095 | |
| 1096 | return mapIt->second; |
| 1097 | } |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 1098 | |
| 1099 | // Configuration retrieval |
| 1100 | CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) |
| 1101 | { |
| 1102 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strConfiguration)); |
| 1103 | |
| 1104 | if (!pDomainConfiguration) { |
| 1105 | |
| 1106 | strError = "Domain configuration " + strConfiguration + " not found"; |
| 1107 | |
| 1108 | return NULL; |
| 1109 | } |
| 1110 | return pDomainConfiguration; |
| 1111 | } |
| 1112 | |
| 1113 | const CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) const |
| 1114 | { |
| 1115 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration)); |
| 1116 | |
| 1117 | if (!pDomainConfiguration) { |
| 1118 | |
| 1119 | strError = "Domain configuration " + strConfiguration + " not found"; |
| 1120 | |
| 1121 | return NULL; |
| 1122 | } |
| 1123 | return pDomainConfiguration; |
| 1124 | } |