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 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 350 | log_info("Adding configurable element \"%s\" into domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 351 | |
| 352 | // Do add |
Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 353 | doAddConfigurableElement(pConfigurableElement, pMainBlackboard); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 354 | |
| 355 | return true; |
| 356 | } |
| 357 | |
| 358 | bool CConfigurableDomain::removeConfigurableElement(CConfigurableElement* pConfigurableElement, string& strError) |
| 359 | { |
| 360 | // Not associated? |
| 361 | if (!containsConfigurableElement(pConfigurableElement)) { |
| 362 | |
| 363 | strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName(); |
| 364 | |
| 365 | return false; |
| 366 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 367 | 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] | 368 | |
| 369 | // Do remove |
| 370 | doRemoveConfigurableElement(pConfigurableElement, true); |
| 371 | |
| 372 | return true; |
| 373 | } |
| 374 | |
Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 375 | /** |
| 376 | * Blackboard Configuration and Base Offset retrieval. |
| 377 | * |
| 378 | * This method fetches the Blackboard associated to the ConfigurableElement |
| 379 | * given in parameter, for a specific Configuration. The ConfigurableElement |
| 380 | * must belong to the Domain. If a Blackboard is found, the base offset of |
| 381 | * the ConfigurableElement is returned as well. This base offset corresponds to |
| 382 | * the offset of the ancestor of the ConfigurableElement associated to the Configuration. |
| 383 | * |
| 384 | * @param[in] strConfiguration Name of the Configuration. |
| 385 | * @param[in] pCandidateDescendantConfigurableElement Pointer to a CConfigurableElement that |
| 386 | * belongs to the Domain. |
| 387 | * @param[out] uiBaseOffset The base offset of the CConfigurableElement. |
| 388 | * @param[out] bIsLastApplied Boolean indicating that the Configuration is |
| 389 | * the last one applied of the Domain. |
| 390 | * @param[out] strError Error message |
| 391 | * |
| 392 | * return Pointer to the Blackboard of the Configuration. |
| 393 | */ |
| 394 | CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const string& strConfiguration, |
| 395 | const CConfigurableElement* pCandidateDescendantConfigurableElement, |
| 396 | uint32_t& uiBaseOffset, |
| 397 | bool& bIsLastApplied, |
| 398 | string& strError) const |
| 399 | { |
| 400 | // Find Configuration |
| 401 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration)); |
| 402 | |
| 403 | if (!pDomainConfiguration) { |
| 404 | |
| 405 | strError = "Domain configuration " + strConfiguration + " not found"; |
| 406 | |
| 407 | return NULL; |
| 408 | } |
| 409 | |
| 410 | // Parse all configurable elements |
| 411 | ConfigurableElementListIterator it; |
| 412 | |
| 413 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 414 | |
| 415 | const CConfigurableElement* pAssociatedConfigurableElement = *it; |
| 416 | |
| 417 | // Check if the the associated element is the configurable element or one of its ancestors |
| 418 | if ((pCandidateDescendantConfigurableElement == pAssociatedConfigurableElement) || |
| 419 | (pCandidateDescendantConfigurableElement->isDescendantOf(pAssociatedConfigurableElement))) { |
| 420 | |
| 421 | uiBaseOffset = pAssociatedConfigurableElement->getOffset(); |
| 422 | bIsLastApplied = (pDomainConfiguration == _pLastAppliedConfiguration); |
| 423 | |
| 424 | return pDomainConfiguration->getBlackboard(pAssociatedConfigurableElement); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | strError = "Element not associated to the Domain"; |
| 429 | |
| 430 | return NULL; |
| 431 | } |
| 432 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 433 | // Domain splitting |
| 434 | bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, string& strError) |
| 435 | { |
| 436 | // Not associated? |
| 437 | if (!containsConfigurableElement(pConfigurableElement)) { |
| 438 | |
| 439 | strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName(); |
| 440 | |
| 441 | return false; |
| 442 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 443 | 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] | 444 | |
| 445 | // Create sub domain areas for all configurable element's children |
| 446 | uint32_t uiNbConfigurableElementChildren = pConfigurableElement->getNbChildren(); |
| 447 | |
| 448 | if (!uiNbConfigurableElementChildren) { |
| 449 | |
| 450 | strError = "Configurable element " + pConfigurableElement->getPath() + " has no children to split configurable domain to"; |
| 451 | |
| 452 | return false; |
| 453 | } |
| 454 | |
| 455 | uint32_t uiChild; |
| 456 | |
| 457 | for (uiChild = 0; uiChild < uiNbConfigurableElementChildren; uiChild++) { |
| 458 | |
| 459 | CConfigurableElement* pChildConfigurableElement = static_cast<CConfigurableElement*>(pConfigurableElement->getChild(uiChild)); |
| 460 | |
| 461 | doAddConfigurableElement(pChildConfigurableElement); |
| 462 | } |
| 463 | |
| 464 | // Delegate to configurations |
| 465 | uint32_t uiNbConfigurations = getNbChildren(); |
| 466 | |
| 467 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 468 | |
| 469 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 470 | |
| 471 | pDomainConfiguration->split(pConfigurableElement); |
| 472 | } |
| 473 | |
| 474 | // Remove given configurable element from this domain |
| 475 | // 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 |
| 476 | doRemoveConfigurableElement(pConfigurableElement, false); |
| 477 | |
| 478 | return true; |
| 479 | } |
| 480 | |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 481 | // Check if there is a pending configuration for this domain: i.e. an applicable configuration different from the last applied configuration |
| 482 | const CDomainConfiguration* CConfigurableDomain::getPendingConfiguration() const |
| 483 | { |
| 484 | const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration(); |
| 485 | |
| 486 | if (pApplicableDomainConfiguration) { |
| 487 | |
| 488 | // Check not the last one before applying |
| 489 | if (!_pLastAppliedConfiguration || (_pLastAppliedConfiguration != pApplicableDomainConfiguration)) { |
| 490 | |
| 491 | return pApplicableDomainConfiguration; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | return NULL; |
| 496 | } |
| 497 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 498 | // Configuration application if required |
Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 499 | void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForce) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 500 | { |
Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 501 | // Apply configuration only if the blackboard will |
| 502 | // be synchronized either now or by syncerSet. |
| 503 | if(!pSyncerSet ^ _bSequenceAware) { |
| 504 | // The configuration can not be syncronised |
| 505 | return; |
| 506 | } |
| 507 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 508 | if (bForce) { |
| 509 | // Force a configuration restore by forgetting about last applied configuration |
| 510 | _pLastAppliedConfiguration = NULL; |
| 511 | } |
| 512 | const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration(); |
| 513 | |
| 514 | if (pApplicableDomainConfiguration) { |
| 515 | |
| 516 | // Check not the last one before applying |
| 517 | if (!_pLastAppliedConfiguration || _pLastAppliedConfiguration != pApplicableDomainConfiguration) { |
| 518 | |
Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 519 | log_info("Applying configuration \"%s\" from domain \"%s\"", |
| 520 | pApplicableDomainConfiguration->getName().c_str(), |
| 521 | getName().c_str()); |
| 522 | |
| 523 | // Check if we need to synchronize during restore |
| 524 | bool bSync = !pSyncerSet && _bSequenceAware; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 525 | |
| 526 | // Do the restore |
Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 527 | pApplicableDomainConfiguration->restore(pParameterBlackboard, bSync, NULL); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 528 | |
| 529 | // Record last applied configuration |
| 530 | _pLastAppliedConfiguration = pApplicableDomainConfiguration; |
| 531 | |
Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 532 | // Check we need to provide syncer set to caller |
| 533 | if (pSyncerSet && !_bSequenceAware) { |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 534 | |
| 535 | // 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] | 536 | *pSyncerSet += _syncerSet; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 537 | } |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | // Return applicable configuration validity for given configurable element |
| 543 | bool CConfigurableDomain::isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const |
| 544 | { |
| 545 | const CDomainConfiguration* pApplicableDomainConfiguration = findApplicableDomainConfiguration(); |
| 546 | |
| 547 | return pApplicableDomainConfiguration && pApplicableDomainConfiguration->isValid(pConfigurableElement); |
| 548 | } |
| 549 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 550 | // In case configurable element was removed |
| 551 | void CConfigurableDomain::computeSyncSet() |
| 552 | { |
| 553 | // Clean sync set first |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 554 | _syncerSet.clear(); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 555 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 556 | // Add syncer sets for all associated configurable elements |
| 557 | ConfigurableElementToSyncerSetMapIterator mapIt; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 558 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 559 | for (mapIt = _configurableElementToSyncerSetMap.begin(); mapIt != _configurableElementToSyncerSetMap.end(); ++mapIt) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 560 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 561 | const CSyncerSet* pSyncerSet = mapIt->second; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 562 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 563 | _syncerSet += *pSyncerSet; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| 567 | // Configuration Management |
| 568 | bool CConfigurableDomain::createConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 569 | { |
| 570 | // Already exists? |
| 571 | if (findChild(strName)) { |
| 572 | |
| 573 | strError = "Already existing configuration"; |
| 574 | |
| 575 | return false; |
| 576 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 577 | 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] | 578 | |
| 579 | // Creation |
| 580 | CDomainConfiguration* pDomainConfiguration = new CDomainConfiguration(strName); |
| 581 | |
| 582 | // Configurable elements association |
| 583 | ConfigurableElementListIterator it; |
| 584 | |
| 585 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 586 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 587 | const CConfigurableElement* pConfigurableElement = *it;; |
| 588 | |
| 589 | // Retrieve associated syncer set |
| 590 | CSyncerSet* pSyncerSet = getSyncerSet(pConfigurableElement); |
| 591 | |
| 592 | // Associate to configuration |
| 593 | pDomainConfiguration->addConfigurableElement(pConfigurableElement, pSyncerSet); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | // Hierarchy |
| 597 | addChild(pDomainConfiguration); |
| 598 | |
| 599 | // Ensure validity of fresh new domain configuration |
| 600 | // Attempt auto validation, so that the user gets his/her own settings by defaults |
| 601 | if (!autoValidateConfiguration(pDomainConfiguration)) { |
| 602 | |
| 603 | // No valid configuration found to copy in from, validate againt main blackboard (will concerned remaining invalid parts) |
| 604 | pDomainConfiguration->validate(pMainBlackboard); |
| 605 | } |
| 606 | |
| 607 | return true; |
| 608 | } |
| 609 | |
| 610 | bool CConfigurableDomain::deleteConfiguration(const string& strName, string& strError) |
| 611 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 612 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 613 | |
| 614 | if (!pDomainConfiguration) { |
| 615 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 616 | return false; |
| 617 | } |
| 618 | |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 619 | 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] | 620 | |
| 621 | // Was the last applied? |
| 622 | if (pDomainConfiguration == _pLastAppliedConfiguration) { |
| 623 | |
| 624 | // Forget about it |
| 625 | _pLastAppliedConfiguration = NULL; |
| 626 | } |
| 627 | |
| 628 | // Hierarchy |
| 629 | removeChild(pDomainConfiguration); |
| 630 | |
| 631 | // Destroy |
| 632 | delete pDomainConfiguration; |
| 633 | |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | void CConfigurableDomain::listAssociatedToElements(string& strResult) const |
| 638 | { |
| 639 | strResult = "\n"; |
| 640 | |
| 641 | ConfigurableElementListIterator it; |
| 642 | |
| 643 | // Browse all configurable elements |
| 644 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 645 | |
| 646 | const CConfigurableElement* pConfigurableElement = *it; |
| 647 | |
| 648 | strResult += pConfigurableElement->getPath() + "\n"; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | bool CConfigurableDomain::renameConfiguration(const string& strName, const string& strNewName, string& strError) |
| 653 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 654 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 655 | |
| 656 | if (!pDomainConfiguration) { |
| 657 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 658 | return false; |
| 659 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 660 | 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] | 661 | |
| 662 | // Rename |
| 663 | return pDomainConfiguration->rename(strNewName, strError); |
| 664 | } |
| 665 | |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 666 | 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] | 667 | { |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 668 | string strError; |
| 669 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 670 | const CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 671 | |
| 672 | if (!pDomainConfiguration) { |
| 673 | |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 674 | lstrError.push_back(strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 675 | return false; |
| 676 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 677 | 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] | 678 | |
| 679 | // Delegate |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 680 | bool bSuccess = pDomainConfiguration->restore(pMainBlackboard, bAutoSync && _bSequenceAware, &lstrError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 681 | |
| 682 | // Record last applied configuration |
| 683 | _pLastAppliedConfiguration = pDomainConfiguration; |
| 684 | |
| 685 | // Synchronize |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 686 | if (bAutoSync && !_bSequenceAware) { |
| 687 | |
| 688 | bSuccess &= _syncerSet.sync(*pMainBlackboard, false, &lstrError); |
| 689 | } |
| 690 | return bSuccess; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | bool CConfigurableDomain::saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 694 | { |
| 695 | // Find Domain configuration |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 696 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 697 | |
| 698 | if (!pDomainConfiguration) { |
| 699 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 700 | return false; |
| 701 | } |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 702 | 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] | 703 | |
| 704 | // Delegate |
| 705 | pDomainConfiguration->save(pMainBlackboard); |
| 706 | |
| 707 | return true; |
| 708 | } |
| 709 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 710 | bool CConfigurableDomain::setElementSequence(const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError) |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 711 | { |
| 712 | // Find Domain configuration |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 713 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 714 | |
| 715 | if (!pDomainConfiguration) { |
| 716 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 717 | return false; |
| 718 | } |
| 719 | |
| 720 | // Delegate to configuration |
| 721 | return pDomainConfiguration->setElementSequence(astrNewElementSequence, strError); |
| 722 | } |
| 723 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 724 | bool CConfigurableDomain::getElementSequence(const string& strConfiguration, string& strResult) const |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 725 | { |
| 726 | // Find Domain configuration |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 727 | const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 728 | |
| 729 | if (!pDomainConfiguration) { |
| 730 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 731 | return false; |
| 732 | } |
| 733 | |
| 734 | // Delegate to configuration |
| 735 | pDomainConfiguration->getElementSequence(strResult); |
| 736 | |
| 737 | return true; |
| 738 | } |
| 739 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 740 | bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) |
| 741 | { |
| 742 | // Find Domain configuration |
| 743 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); |
| 744 | |
| 745 | if (!pDomainConfiguration) { |
| 746 | |
| 747 | return false; |
| 748 | } |
| 749 | |
| 750 | // Delegate to configuration |
| 751 | return pDomainConfiguration->setApplicationRule(strApplicationRule, pSelectionCriteriaDefinition, strError); |
| 752 | } |
| 753 | |
| 754 | bool CConfigurableDomain::clearApplicationRule(const string& strConfiguration, string& strError) |
| 755 | { |
| 756 | // Find Domain configuration |
| 757 | CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); |
| 758 | |
| 759 | if (!pDomainConfiguration) { |
| 760 | |
| 761 | return false; |
| 762 | } |
| 763 | |
| 764 | // Delegate to configuration |
| 765 | pDomainConfiguration->clearApplicationRule(); |
| 766 | |
| 767 | return true; |
| 768 | } |
| 769 | |
| 770 | bool CConfigurableDomain::getApplicationRule(const string& strConfiguration, string& strResult) const |
| 771 | { |
| 772 | // Find Domain configuration |
| 773 | const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult); |
| 774 | |
| 775 | if (!pDomainConfiguration) { |
| 776 | |
| 777 | return false; |
| 778 | } |
| 779 | |
| 780 | // Delegate to configuration |
| 781 | pDomainConfiguration->getApplicationRule(strResult); |
| 782 | |
| 783 | return true; |
| 784 | } |
| 785 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 786 | // Last applied configuration |
| 787 | string CConfigurableDomain::getLastAppliedConfigurationName() const |
| 788 | { |
| 789 | if (_pLastAppliedConfiguration) { |
| 790 | |
| 791 | return _pLastAppliedConfiguration->getName(); |
| 792 | } |
| 793 | return "<none>"; |
| 794 | } |
| 795 | |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 796 | // Pending configuration |
| 797 | string CConfigurableDomain::getPendingConfigurationName() const |
| 798 | { |
| 799 | const CDomainConfiguration* pPendingConfiguration = getPendingConfiguration(); |
| 800 | |
| 801 | if (pPendingConfiguration) { |
| 802 | |
| 803 | return pPendingConfiguration->getName(); |
| 804 | } |
| 805 | return "<none>"; |
| 806 | } |
| 807 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 808 | // Ensure validity on whole domain from main blackboard |
| 809 | void CConfigurableDomain::validate(const CParameterBlackboard* pMainBlackboard) |
| 810 | { |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 811 | log_info("Validating whole domain \"" + getName() + "\" against main blackboard"); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 812 | |
| 813 | // Propagate |
| 814 | uint32_t uiNbConfigurations = getNbChildren(); |
| 815 | uint32_t uiChild; |
| 816 | |
| 817 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 818 | |
| 819 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 820 | |
| 821 | pDomainConfiguration->validate(pMainBlackboard); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | // Ensure validity on areas related to configurable element |
| 826 | void CConfigurableDomain::validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) |
| 827 | { |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 828 | 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] | 829 | |
| 830 | // Propagate |
| 831 | uint32_t uiNbConfigurations = getNbChildren(); |
| 832 | uint32_t uiChild; |
| 833 | |
| 834 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 835 | |
| 836 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 837 | |
| 838 | pDomainConfiguration->validate(pConfigurableElement, pMainBlackboard); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | // Attempt validation for all configurable element's areas, relying on already existing valid configuration inside domain |
| 843 | void CConfigurableDomain::autoValidateAll() |
| 844 | { |
| 845 | // Validate |
| 846 | ConfigurableElementListIterator it; |
| 847 | |
| 848 | // Browse all configurable elements for configuration validation |
| 849 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 850 | |
| 851 | const CConfigurableElement* pConfigurableElement = *it; |
| 852 | |
| 853 | // Auto validate element |
| 854 | autoValidateAreas(pConfigurableElement); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | // Attempt validation for configurable element's areas, relying on already existing valid configuration inside domain |
| 859 | void CConfigurableDomain::autoValidateAreas(const CConfigurableElement* pConfigurableElement) |
| 860 | { |
| 861 | // Find first valid configuration for given configurable element |
| 862 | const CDomainConfiguration* pValidDomainConfiguration = findValidDomainConfiguration(pConfigurableElement); |
| 863 | |
| 864 | // No valid configuration found, give up |
| 865 | if (!pValidDomainConfiguration) { |
| 866 | |
| 867 | return; |
| 868 | } |
| 869 | |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 870 | log_info("Auto validating domain \"" + getName() + "\" against configuration \"" + pValidDomainConfiguration->getName() + "\" for configurable element " + pConfigurableElement->getPath()); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 871 | |
| 872 | // Validate all other configurations against found one, if any |
| 873 | uint32_t uiNbConfigurations = getNbChildren(); |
| 874 | uint32_t uiChild; |
| 875 | |
| 876 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 877 | |
| 878 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 879 | |
| 880 | if (pDomainConfiguration != pValidDomainConfiguration && !pDomainConfiguration->isValid(pConfigurableElement)) { |
| 881 | // Validate |
| 882 | pDomainConfiguration->validateAgainst(pValidDomainConfiguration, pConfigurableElement); |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | // Attempt configuration validation for all configurable elements' areas, relying on already existing valid configuration inside domain |
| 888 | bool CConfigurableDomain::autoValidateConfiguration(CDomainConfiguration* pDomainConfiguration) |
| 889 | { |
| 890 | // Find another configuration than this one, that ought to be valid! |
| 891 | uint32_t uiNbConfigurations = getNbChildren(); |
| 892 | uint32_t uiChild; |
| 893 | |
| 894 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 895 | |
| 896 | const CDomainConfiguration* pPotententialValidDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); |
| 897 | |
| 898 | if (pPotententialValidDomainConfiguration != pDomainConfiguration) { |
| 899 | |
| 900 | // Validate against it |
| 901 | pDomainConfiguration->validateAgainst(pPotententialValidDomainConfiguration); |
| 902 | |
| 903 | return true; |
| 904 | } |
| 905 | } |
| 906 | return false; |
| 907 | } |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 908 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 909 | // Search for a valid configuration for given configurable element |
| 910 | const CDomainConfiguration* CConfigurableDomain::findValidDomainConfiguration(const CConfigurableElement* pConfigurableElement) const |
| 911 | { |
| 912 | uint32_t uiNbConfigurations = getNbChildren(); |
| 913 | uint32_t uiChild; |
| 914 | |
| 915 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 916 | |
| 917 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); |
| 918 | |
| 919 | if (pDomainConfiguration->isValid(pConfigurableElement)) { |
| 920 | |
| 921 | return pDomainConfiguration; |
| 922 | } |
| 923 | } |
| 924 | return NULL; |
| 925 | } |
| 926 | |
| 927 | // Search for an applicable configuration |
| 928 | const CDomainConfiguration* CConfigurableDomain::findApplicableDomainConfiguration() const |
| 929 | { |
| 930 | uint32_t uiNbConfigurations = getNbChildren(); |
| 931 | uint32_t uiChild; |
| 932 | |
| 933 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 934 | |
| 935 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); |
| 936 | |
| 937 | if (pDomainConfiguration->isApplicable()) { |
| 938 | |
| 939 | return pDomainConfiguration; |
| 940 | } |
| 941 | } |
| 942 | return NULL; |
| 943 | } |
| 944 | |
| 945 | // Gather set of configurable elements |
| 946 | void CConfigurableDomain::gatherConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const |
| 947 | { |
| 948 | // Insert all configurable elements |
| 949 | configurableElementSet.insert(_configurableElementList.begin(), _configurableElementList.end()); |
| 950 | } |
| 951 | |
| 952 | // Check configurable element already attached |
| 953 | bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const |
| 954 | { |
| 955 | ConfigurableElementListIterator it; |
| 956 | |
| 957 | // Browse all configurable elements for comparison |
| 958 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 959 | |
| 960 | if (pConfigurableCandidateElement == *it) { |
| 961 | |
| 962 | return true; |
| 963 | } |
| 964 | } |
| 965 | return false; |
| 966 | } |
| 967 | |
| 968 | // Merge any descended configurable element to this one with this one |
| 969 | void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement) |
| 970 | { |
| 971 | list<CConfigurableElement*> mergedConfigurableElementList; |
| 972 | |
| 973 | ConfigurableElementListIterator it; |
| 974 | |
| 975 | // Browse all configurable elements (new one not yet in the list!) |
| 976 | for (it = _configurableElementList.begin(); it != _configurableElementList.end(); ++it) { |
| 977 | |
| 978 | CConfigurableElement* pConfigurablePotentialDescendantElement = *it; |
| 979 | |
| 980 | if (pConfigurablePotentialDescendantElement->isDescendantOf(pNewConfigurableElement)) { |
| 981 | |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 982 | 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] | 983 | |
| 984 | // Merge configuration data |
| 985 | mergeConfigurations(pNewConfigurableElement, pConfigurablePotentialDescendantElement); |
| 986 | |
| 987 | // Keep track for removal |
| 988 | mergedConfigurableElementList.push_back(pConfigurablePotentialDescendantElement); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | // Remove all merged elements (new one not yet in the list!) |
| 993 | for (it = mergedConfigurableElementList.begin(); it != mergedConfigurableElementList.end(); ++it) { |
| 994 | |
| 995 | CConfigurableElement* pMergedConfigurableElement = *it; |
| 996 | |
| 997 | // Remove merged from configurable element from internal tracking list |
| 998 | // 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 |
| 999 | doRemoveConfigurableElement(pMergedConfigurableElement, false); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement) |
| 1004 | { |
| 1005 | // Propagate to domain configurations |
| 1006 | uint32_t uiNbConfigurations = getNbChildren(); |
| 1007 | uint32_t uiChild; |
| 1008 | |
| 1009 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 1010 | |
| 1011 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 1012 | |
| 1013 | // Do the merge. |
| 1014 | pDomainConfiguration->merge(pToConfigurableElement, pFromConfigurableElement); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | // Configurable elements association |
Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 1019 | void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard *pMainBlackboard) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1020 | { |
| 1021 | // Inform configurable element |
| 1022 | pConfigurableElement->addAttachedConfigurableDomain(this); |
| 1023 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1024 | // Create associated syncer set |
| 1025 | CSyncerSet* pSyncerSet = new CSyncerSet; |
| 1026 | |
| 1027 | // Add to sync set the configurable element one |
| 1028 | pConfigurableElement->fillSyncerSet(*pSyncerSet); |
| 1029 | |
| 1030 | // Store it |
| 1031 | _configurableElementToSyncerSetMap[pConfigurableElement] = pSyncerSet; |
| 1032 | |
| 1033 | // Add it to global one |
| 1034 | _syncerSet += *pSyncerSet; |
| 1035 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1036 | // Inform configurations |
| 1037 | uint32_t uiNbConfigurations = getNbChildren(); |
| 1038 | uint32_t uiChild; |
| 1039 | |
| 1040 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 1041 | |
| 1042 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 1043 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1044 | pDomainConfiguration->addConfigurableElement(pConfigurableElement, pSyncerSet); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1045 | } |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1046 | |
Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 1047 | // Ensure area validity for that configurable element (if main blackboard provided) |
| 1048 | if (pMainBlackboard) { |
| 1049 | |
| 1050 | // Need to validate against main blackboard |
| 1051 | validateAreas(pConfigurableElement, pMainBlackboard); |
| 1052 | } |
| 1053 | |
| 1054 | // Already associated descendend configurable elements need a merge of their configuration data |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1055 | mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement); |
| 1056 | |
| 1057 | // Add to list |
| 1058 | _configurableElementList.push_back(pConfigurableElement); |
| 1059 | } |
| 1060 | |
| 1061 | void CConfigurableDomain::doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet) |
| 1062 | { |
| 1063 | // Remove from list |
| 1064 | _configurableElementList.remove(pConfigurableElement); |
| 1065 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1066 | // Remove associated syncer set |
| 1067 | CSyncerSet* pSyncerSet = getSyncerSet(pConfigurableElement); |
| 1068 | |
| 1069 | _configurableElementToSyncerSetMap.erase(pConfigurableElement); |
| 1070 | |
| 1071 | delete pSyncerSet; |
| 1072 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1073 | // Inform configurable element |
| 1074 | pConfigurableElement->removeAttachedConfigurableDomain(this); |
| 1075 | |
| 1076 | // Inform configurations |
| 1077 | uint32_t uiNbConfigurations = getNbChildren(); |
| 1078 | uint32_t uiChild; |
| 1079 | |
| 1080 | for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { |
| 1081 | |
| 1082 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(getChild(uiChild)); |
| 1083 | |
| 1084 | pDomainConfiguration->removeConfigurableElement(pConfigurableElement); |
| 1085 | } |
| 1086 | // Recompute our sync set if needed |
| 1087 | if (bRecomputeSyncSet) { |
| 1088 | |
| 1089 | computeSyncSet(); |
| 1090 | } |
| 1091 | } |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 1092 | |
| 1093 | // Syncer set retrieval from configurable element |
| 1094 | CSyncerSet* CConfigurableDomain::getSyncerSet(const CConfigurableElement* pConfigurableElement) const |
| 1095 | { |
| 1096 | ConfigurableElementToSyncerSetMapIterator mapIt = _configurableElementToSyncerSetMap.find(pConfigurableElement); |
| 1097 | |
| 1098 | assert(mapIt != _configurableElementToSyncerSetMap.end()); |
| 1099 | |
| 1100 | return mapIt->second; |
| 1101 | } |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 1102 | |
| 1103 | // Configuration retrieval |
| 1104 | CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) |
| 1105 | { |
| 1106 | CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strConfiguration)); |
| 1107 | |
| 1108 | if (!pDomainConfiguration) { |
| 1109 | |
| 1110 | strError = "Domain configuration " + strConfiguration + " not found"; |
| 1111 | |
| 1112 | return NULL; |
| 1113 | } |
| 1114 | return pDomainConfiguration; |
| 1115 | } |
| 1116 | |
| 1117 | const CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) const |
| 1118 | { |
| 1119 | const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration)); |
| 1120 | |
| 1121 | if (!pDomainConfiguration) { |
| 1122 | |
| 1123 | strError = "Domain configuration " + strConfiguration + " not found"; |
| 1124 | |
| 1125 | return NULL; |
| 1126 | } |
| 1127 | return pDomainConfiguration; |
| 1128 | } |