| David Wagner | b76c9d6 | 2014-02-05 18:30:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2014, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without modification, |
| 6 | * are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | * list of conditions and the following disclaimer. |
| 10 | * |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer in the documentation and/or |
| 13 | * other materials provided with the distribution. |
| 14 | * |
| 15 | * 3. Neither the name of the copyright holder nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software without |
| 17 | * specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 29 | */ |
| 30 | #include "DomainConfiguration.h" |
| 31 | #include "AreaConfiguration.h" |
| 32 | #include "ConfigurableElement.h" |
| 33 | #include "CompoundRule.h" |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 34 | #include "Subsystem.h" |
| 35 | #include "XmlDomainSerializingContext.h" |
| 36 | #include "ConfigurationAccessContext.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 37 | #include <assert.h> |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 38 | #include "RuleParser.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 39 | |
| 40 | #define base CBinarySerializableElement |
| 41 | |
| 42 | CDomainConfiguration::CDomainConfiguration(const string& strName) : base(strName) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | CDomainConfiguration::~CDomainConfiguration() |
| 47 | { |
| 48 | AreaConfigurationListIterator it; |
| 49 | |
| 50 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 51 | |
| 52 | delete *it; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // Class kind |
| 57 | string CDomainConfiguration::getKind() const |
| 58 | { |
| 59 | return "Configuration"; |
| 60 | } |
| 61 | |
| 62 | // Child dynamic creation |
| 63 | bool CDomainConfiguration::childrenAreDynamic() const |
| 64 | { |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | // XML configuration settings parsing |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 69 | bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 70 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 71 | // Actual XML context |
| 72 | CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<CXmlDomainSerializingContext&>(serializingContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 73 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 74 | // Take care of configurable elements / area configurations ranks |
| 75 | list<CAreaConfiguration*> areaConfigurationList; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 76 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 77 | // Parse configurable element's configuration settings |
| 78 | CXmlElement::CChildIterator it(xmlConfigurationSettingsElement); |
| 79 | |
| 80 | CXmlElement xmlConfigurableElementSettingsElement; |
| 81 | |
| 82 | while (it.next(xmlConfigurableElementSettingsElement)) { |
| 83 | |
| 84 | // Retrieve area configuration |
| 85 | string strConfigurableElementPath = xmlConfigurableElementSettingsElement.getAttributeString("Path"); |
| 86 | |
| 87 | CAreaConfiguration* pAreaConfiguration = findAreaConfiguration(strConfigurableElementPath); |
| 88 | |
| 89 | if (!pAreaConfiguration) { |
| 90 | |
| 91 | xmlDomainSerializingContext.setError("Configurable Element " + strConfigurableElementPath + " referred to by Configuration " + getPath() + " not associated to Domain"); |
| 92 | |
| 93 | return false; |
| 94 | } |
| 95 | // Ranks |
| 96 | areaConfigurationList.push_back(pAreaConfiguration); |
| 97 | |
| 98 | // Parse |
| 99 | if (!serializeConfigurableElementSettings(pAreaConfiguration, xmlConfigurableElementSettingsElement, xmlDomainSerializingContext, false)) { |
| 100 | |
| 101 | return false; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // Reorder area configurations according to XML content |
| 106 | reorderAreaConfigurations(areaConfigurationList); |
| 107 | |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | // XML configuration settings composing |
| 112 | void CDomainConfiguration::composeSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext) const |
| 113 | { |
| 114 | // Go through all are configurations |
| 115 | AreaConfigurationListIterator it; |
| 116 | |
| 117 | for (it = _orderedAreaConfigurationList.begin(); it != _orderedAreaConfigurationList.end(); ++it) { |
| 118 | |
| 119 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 120 | |
| 121 | // Retrieve configurable element |
| 122 | const CConfigurableElement* pConfigurableElement = pAreaConfiguration->getConfigurableElement(); |
| 123 | |
| 124 | // Create configurable element child element |
| 125 | CXmlElement xmlConfigurableElementSettingsElement; |
| 126 | |
| 127 | xmlConfigurationSettingsElement.createChild(xmlConfigurableElementSettingsElement, "ConfigurableElement"); |
| 128 | |
| 129 | // Set Path attribute |
| 130 | xmlConfigurableElementSettingsElement.setAttributeString("Path", pConfigurableElement->getPath()); |
| 131 | |
| 132 | // Delegate composing to area configuration |
| 133 | ((CDomainConfiguration&)(*this)).serializeConfigurableElementSettings((CAreaConfiguration*)pAreaConfiguration, xmlConfigurableElementSettingsElement, serializingContext, true); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // Serialize one configuration for one configurable element |
| 138 | bool CDomainConfiguration::serializeConfigurableElementSettings(CAreaConfiguration* pAreaConfiguration, CXmlElement& xmlConfigurableElementSettingsElement, CXmlSerializingContext& serializingContext, bool bSerializeOut) |
| 139 | { |
| 140 | // Actual XML context |
| 141 | CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast<CXmlDomainSerializingContext&>(serializingContext); |
| 142 | |
| 143 | // Configurable Element |
| 144 | const CConfigurableElement* pConfigurableElement = pAreaConfiguration->getConfigurableElement(); |
| 145 | |
| 146 | // Element content |
| 147 | CXmlElement xmlConfigurableElementSettingsElementContent; |
| 148 | |
| 149 | // Deal with element itself |
| 150 | if (!bSerializeOut) { |
| 151 | |
| 152 | // Check structure |
| 153 | if (xmlConfigurableElementSettingsElement.getNbChildElements() != 1) { |
| 154 | |
| 155 | // Structure error |
| 156 | serializingContext.setError("Struture error encountered while parsing settings of " + pConfigurableElement->getKind() + " " + pConfigurableElement->getName() + " in Configuration " + getPath()); |
| 157 | |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | // Check name and kind |
| 162 | if (!xmlConfigurableElementSettingsElement.getChildElement(pConfigurableElement->getKind(), pConfigurableElement->getName(), xmlConfigurableElementSettingsElementContent)) { |
| 163 | |
| 164 | serializingContext.setError("Couldn't find settings for " + pConfigurableElement->getKind() + " " + pConfigurableElement->getName() + " for Configuration " + getPath()); |
| 165 | |
| 166 | return false; |
| 167 | } |
| 168 | } else { |
| 169 | |
| 170 | // Create child XML element |
| 171 | xmlConfigurableElementSettingsElement.createChild(xmlConfigurableElementSettingsElementContent, pConfigurableElement->getKind()); |
| 172 | |
| 173 | // Set Name |
| 174 | xmlConfigurableElementSettingsElementContent.setNameAttribute(pConfigurableElement->getName()); |
| 175 | } |
| 176 | |
| 177 | // Change context type to parameter settings access |
| 178 | string strError; |
| 179 | |
| 180 | // Create configuration access context |
| 181 | CConfigurationAccessContext configurationAccessContext(strError, bSerializeOut); |
| 182 | |
| 183 | // Provide current value space |
| 184 | configurationAccessContext.setValueSpaceRaw(xmlDomainSerializingContext.valueSpaceIsRaw()); |
| 185 | |
| 186 | // Provide current output raw format |
| 187 | configurationAccessContext.setOutputRawFormat(xmlDomainSerializingContext.outputRawFormatIsHex()); |
| 188 | |
| 189 | // Get subsystem |
| 190 | const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem(); |
| 191 | |
| 192 | if (pSubsystem && pSubsystem != pConfigurableElement) { |
| 193 | |
| 194 | // Element is a descendant of subsystem |
| 195 | |
| 196 | // Deal with Endianness |
| 197 | configurationAccessContext.setBigEndianSubsystem(pSubsystem->isBigEndian()); |
| 198 | } |
| 199 | |
| 200 | // Have domain configuration parse settings for configurable element |
| 201 | if (!pAreaConfiguration->serializeXmlSettings(xmlConfigurableElementSettingsElementContent, configurationAccessContext)) { |
| 202 | |
| 203 | // Forward error |
| 204 | xmlDomainSerializingContext.setError(strError); |
| 205 | |
| 206 | return false; |
| 207 | } |
| 208 | return true; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Configurable Elements association |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 212 | void CDomainConfiguration::addConfigurableElement(const CConfigurableElement* pConfigurableElement, const CSyncerSet* pSyncerSet) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 213 | { |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 214 | CAreaConfiguration* pAreaConfiguration = pConfigurableElement->createAreaConfiguration(pSyncerSet); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 215 | |
| 216 | _areaConfigurationList.push_back(pAreaConfiguration); |
| 217 | _orderedAreaConfigurationList.push_back(pAreaConfiguration); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void CDomainConfiguration::removeConfigurableElement(const CConfigurableElement* pConfigurableElement) |
| 221 | { |
| 222 | CAreaConfiguration* pAreaConfigurationToRemove = getAreaConfiguration(pConfigurableElement); |
| 223 | |
| 224 | _areaConfigurationList.remove(pAreaConfigurationToRemove); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 225 | _orderedAreaConfigurationList.remove(pAreaConfigurationToRemove); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 226 | |
| 227 | delete pAreaConfigurationToRemove; |
| 228 | } |
| 229 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 230 | // Sequence management |
| 231 | bool CDomainConfiguration::setElementSequence(const vector<string>& astrNewElementSequence, string& strError) |
| 232 | { |
| 233 | // Build a new list of AreaConfiguration objects |
| 234 | list<CAreaConfiguration*> areaConfigurationList; |
| 235 | |
| 236 | uint32_t uiConfigurableElement; |
| 237 | |
| 238 | for (uiConfigurableElement = 0; uiConfigurableElement < astrNewElementSequence.size(); uiConfigurableElement++) { |
| 239 | |
| 240 | string strConfigurableElementPath = astrNewElementSequence[uiConfigurableElement]; |
| 241 | |
| 242 | CAreaConfiguration* pAreaConfiguration = findAreaConfiguration(strConfigurableElementPath); |
| 243 | |
| 244 | if (!pAreaConfiguration) { |
| 245 | |
| 246 | strError = "Element " + strConfigurableElementPath + " not found in domain"; |
| 247 | |
| 248 | return false; |
| 249 | } |
| 250 | // Check not already present in the list |
| 251 | if (findAreaConfiguration(strConfigurableElementPath, areaConfigurationList)) { |
| 252 | |
| 253 | strError = "Element " + strConfigurableElementPath + " provided more than once"; |
| 254 | |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | // Store new ordered area configuration |
| 259 | areaConfigurationList.push_back(pAreaConfiguration); |
| 260 | } |
| 261 | |
| 262 | // Reorder area configurations according to given path list |
| 263 | reorderAreaConfigurations(areaConfigurationList); |
| 264 | |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | void CDomainConfiguration::getElementSequence(string& strResult) const |
| 269 | { |
| 270 | strResult = "\n"; |
| 271 | |
| 272 | AreaConfigurationListIterator it; |
| 273 | |
| 274 | // List configurable element paths out of ordered area configuration list |
| 275 | for (it = _orderedAreaConfigurationList.begin(); it != _orderedAreaConfigurationList.end(); ++it) { |
| 276 | |
| 277 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 278 | |
| 279 | const CConfigurableElement* pConfigurableElement = pAreaConfiguration->getConfigurableElement(); |
| 280 | |
| 281 | strResult += pConfigurableElement->getPath() + "\n"; |
| 282 | } |
| 283 | } |
| 284 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 285 | // Application rule |
| 286 | bool CDomainConfiguration::setApplicationRule(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) |
| 287 | { |
| 288 | // Parser |
| 289 | CRuleParser ruleParser(strApplicationRule, pSelectionCriteriaDefinition); |
| 290 | |
| 291 | // Attempt to parse it |
| 292 | if (!ruleParser.parse(NULL, strError)) { |
| 293 | |
| 294 | return false; |
| 295 | } |
| 296 | // Replace compound rule |
| 297 | setRule(ruleParser.grabRootRule()); |
| 298 | |
| 299 | return true; |
| 300 | } |
| 301 | |
| 302 | void CDomainConfiguration::clearApplicationRule() |
| 303 | { |
| 304 | // Replace compound rule |
| 305 | setRule(NULL); |
| 306 | } |
| 307 | |
| 308 | void CDomainConfiguration::getApplicationRule(string& strResult) const |
| 309 | { |
| 310 | // Rule |
| 311 | const CCompoundRule* pRule = getRule(); |
| 312 | |
| 313 | if (pRule) { |
| 314 | // Start clear |
| 315 | strResult.clear(); |
| 316 | |
| 317 | // Dump rule |
| 318 | pRule->dump(strResult); |
| 319 | |
| 320 | } else { |
| 321 | |
| 322 | strResult = "<none>"; |
| 323 | } |
| 324 | } |
| 325 | |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 326 | /** |
| 327 | * Get the Configuration Blackboard. |
| 328 | * |
| 329 | * Fetch the Configuration Blackboard related to the ConfigurableElement given in parameter. This |
| 330 | * Element is used to retrieve the correct AreaConfiguration where the Blackboard is stored. |
| 331 | * |
| 332 | * @param[in] pConfigurableElement A pointer to a ConfigurableElement that is part of the |
| 333 | * Domain. This must have been checked previously, as an |
| 334 | * assertion is performed. |
| 335 | * |
| 336 | * return Pointer to the Blackboard of the Configuration. |
| 337 | */ |
| 338 | CParameterBlackboard* CDomainConfiguration::getBlackboard(const CConfigurableElement* pConfigurableElement) const |
| 339 | { |
| 340 | AreaConfigurationListIterator it; |
| 341 | |
| 342 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 343 | |
| 344 | CAreaConfiguration* pAreaConfiguration = *it; |
| 345 | |
| 346 | // Check if the Element is associated with the Domain |
| 347 | if (pAreaConfiguration->getConfigurableElement() == pConfigurableElement) { |
| 348 | |
| 349 | return &pAreaConfiguration->getBlackboard(); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | assert(0); |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 357 | // Save data from current |
| 358 | void CDomainConfiguration::save(const CParameterBlackboard* pMainBlackboard) |
| 359 | { |
| 360 | AreaConfigurationListIterator it; |
| 361 | |
| 362 | // Just propagate to areas |
| 363 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 364 | |
| 365 | CAreaConfiguration* pAreaConfiguration = *it; |
| 366 | |
| 367 | pAreaConfiguration->save(pMainBlackboard); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // Apply data to current |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 372 | bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool bSync, list<string>* plstrError) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 373 | { |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 374 | bool bSuccess = true; |
| 375 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 376 | AreaConfigurationListIterator it; |
| 377 | |
| 378 | // Just propagate to areas |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 379 | for (it = _orderedAreaConfigurationList.begin(); it != _orderedAreaConfigurationList.end(); ++it) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 380 | |
| 381 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 382 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 383 | bSuccess &= pAreaConfiguration->restore(pMainBlackboard, bSync, plstrError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 384 | } |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 385 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 386 | return bSuccess; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | // Ensure validity for configurable element area configuration |
| 390 | void CDomainConfiguration::validate(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) |
| 391 | { |
| 392 | CAreaConfiguration* pAreaConfigurationToValidate = getAreaConfiguration(pConfigurableElement); |
| 393 | |
| 394 | // Delegate |
| 395 | pAreaConfigurationToValidate->validate(pMainBlackboard); |
| 396 | } |
| 397 | |
| 398 | // Ensure validity of all area configurations |
| 399 | void CDomainConfiguration::validate(const CParameterBlackboard* pMainBlackboard) |
| 400 | { |
| 401 | AreaConfigurationListIterator it; |
| 402 | |
| 403 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 404 | |
| 405 | CAreaConfiguration* pAreaConfiguration = *it; |
| 406 | |
| 407 | pAreaConfiguration->validate(pMainBlackboard); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | // Return configuration validity for given configurable element |
| 412 | bool CDomainConfiguration::isValid(const CConfigurableElement* pConfigurableElement) const |
| 413 | { |
| 414 | // Get child configurable elemnt's area configuration |
| 415 | CAreaConfiguration* pAreaConfiguration = getAreaConfiguration(pConfigurableElement); |
| 416 | |
| 417 | assert(pAreaConfiguration); |
| 418 | |
| 419 | return pAreaConfiguration->isValid(); |
| 420 | } |
| 421 | |
| 422 | // Ensure validity of configurable element's area configuration by copying in from a valid one |
| 423 | void CDomainConfiguration::validateAgainst(const CDomainConfiguration* pValidDomainConfiguration, const CConfigurableElement* pConfigurableElement) |
| 424 | { |
| 425 | // Retrieve related area configurations |
| 426 | CAreaConfiguration* pAreaConfigurationToValidate = getAreaConfiguration(pConfigurableElement); |
| 427 | const CAreaConfiguration* pAreaConfigurationToValidateAgainst = pValidDomainConfiguration->getAreaConfiguration(pConfigurableElement); |
| 428 | |
| 429 | // Delegate to area |
| 430 | pAreaConfigurationToValidate->validateAgainst(pAreaConfigurationToValidateAgainst); |
| 431 | } |
| 432 | |
| 433 | // Ensure validity of all configurable element's area configuration by copying in from a valid ones |
| 434 | void CDomainConfiguration::validateAgainst(const CDomainConfiguration* pValidDomainConfiguration) |
| 435 | { |
| 436 | // Copy in configuration data from against domain |
| 437 | AreaConfigurationListIterator it, itAgainst; |
| 438 | |
| 439 | for (it = _areaConfigurationList.begin(), itAgainst = pValidDomainConfiguration->_areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it, ++itAgainst) { |
| 440 | |
| 441 | CAreaConfiguration* pAreaConfigurationToValidate = *it; |
| 442 | const CAreaConfiguration* pAreaConfigurationToValidateAgainst = *itAgainst; |
| 443 | |
| 444 | // Delegate to area |
| 445 | pAreaConfigurationToValidate->validateAgainst(pAreaConfigurationToValidateAgainst); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // Dynamic data application |
| 450 | bool CDomainConfiguration::isApplicable() const |
| 451 | { |
| 452 | const CCompoundRule* pRule = getRule(); |
| 453 | |
| 454 | return pRule && pRule->matches(); |
| 455 | } |
| 456 | |
| 457 | // Merge existing configurations to given configurable element ones |
| 458 | void CDomainConfiguration::merge(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement) |
| 459 | { |
| 460 | // Retrieve related area configurations |
| 461 | CAreaConfiguration* pAreaConfigurationToMergeTo = getAreaConfiguration(pToConfigurableElement); |
| 462 | const CAreaConfiguration* pAreaConfigurationToMergeFrom = getAreaConfiguration(pFromConfigurableElement); |
| 463 | |
| 464 | // Do the merge |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 465 | pAreaConfigurationToMergeFrom->copyToOuter(pAreaConfigurationToMergeTo); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | // Domain splitting |
| 469 | void CDomainConfiguration::split(CConfigurableElement* pFromConfigurableElement) |
| 470 | { |
| 471 | // Retrieve related area configuration |
| 472 | const CAreaConfiguration* pAreaConfigurationToSplitFrom = getAreaConfiguration(pFromConfigurableElement); |
| 473 | |
| 474 | // Go through children areas to copy configuration data to them |
| 475 | uint32_t uiNbConfigurableElementChildren = pFromConfigurableElement->getNbChildren(); |
| 476 | uint32_t uiChild; |
| 477 | |
| 478 | for (uiChild = 0; uiChild < uiNbConfigurableElementChildren; uiChild++) { |
| 479 | |
| 480 | CConfigurableElement* pToChildConfigurableElement = static_cast<CConfigurableElement*>(pFromConfigurableElement->getChild(uiChild)); |
| 481 | |
| 482 | // Get child configurable elemnt's area configuration |
| 483 | CAreaConfiguration* pChildAreaConfiguration = getAreaConfiguration(pToChildConfigurableElement); |
| 484 | |
| 485 | // Do the copy |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 486 | pChildAreaConfiguration->copyFromOuter(pAreaConfigurationToSplitFrom); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | // AreaConfiguration retrieval from configurable element |
| 491 | CAreaConfiguration* CDomainConfiguration::getAreaConfiguration(const CConfigurableElement* pConfigurableElement) const |
| 492 | { |
| 493 | AreaConfigurationListIterator it; |
| 494 | |
| 495 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 496 | |
| 497 | CAreaConfiguration* pAreaConfiguration = *it; |
| 498 | |
| 499 | if (pAreaConfiguration->getConfigurableElement() == pConfigurableElement) { |
| 500 | |
| 501 | return pAreaConfiguration; |
| 502 | } |
| 503 | } |
| 504 | // Not found? |
| 505 | assert(0); |
| 506 | |
| 507 | return NULL; |
| 508 | } |
| 509 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 510 | // AreaConfiguration retrieval from present area configurations |
| 511 | CAreaConfiguration* CDomainConfiguration::findAreaConfiguration(const string& strConfigurableElementPath) const |
| 512 | { |
| Patrick Benavoli | 4bed921 | 2011-10-27 14:18:00 +0200 | [diff] [blame] | 513 | return findAreaConfiguration(strConfigurableElementPath, _areaConfigurationList); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | // AreaConfiguration retrieval from given area configuration list |
| 517 | CAreaConfiguration* CDomainConfiguration::findAreaConfiguration(const string& strConfigurableElementPath, const list<CAreaConfiguration*>& areaConfigurationList) const |
| 518 | { |
| 519 | AreaConfigurationListIterator it; |
| 520 | |
| 521 | for (it = areaConfigurationList.begin(); it != areaConfigurationList.end(); ++it) { |
| 522 | |
| 523 | CAreaConfiguration* pAreaConfiguration = *it; |
| 524 | |
| 525 | if (pAreaConfiguration->getConfigurableElement()->getPath() == strConfigurableElementPath) { |
| 526 | |
| 527 | return pAreaConfiguration; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | // Not found |
| 532 | return NULL; |
| 533 | } |
| 534 | |
| 535 | // Area configuration ordering |
| 536 | void CDomainConfiguration::reorderAreaConfigurations(const list<CAreaConfiguration*>& areaConfigurationList) |
| 537 | { |
| 538 | // Ensure elements in provided list appear first and ordered the same way in internal one |
| 539 | |
| 540 | // Remove all elements present in the provided list from the internal one |
| 541 | AreaConfigurationListIterator it; |
| 542 | |
| 543 | for (it = areaConfigurationList.begin(); it != areaConfigurationList.end(); ++it) { |
| 544 | |
| 545 | _orderedAreaConfigurationList.remove(*it); |
| 546 | } |
| 547 | |
| 548 | // Prepended provided elements into internal list |
| 549 | _orderedAreaConfigurationList.insert(_orderedAreaConfigurationList.begin(), areaConfigurationList.begin(), areaConfigurationList.end()); |
| 550 | } |
| 551 | |
| 552 | // Find area configuration rank from regular list: for ordered list maintainance |
| 553 | uint32_t CDomainConfiguration::getAreaConfigurationRank(const CAreaConfiguration* pAreaConfiguration) const |
| 554 | { |
| 555 | uint32_t uiAreaConfigurationRank; |
| 556 | AreaConfigurationListIterator it; |
| 557 | |
| 558 | // Propagate request to areas |
| 559 | for (it = _areaConfigurationList.begin(), uiAreaConfigurationRank = 0; it != _areaConfigurationList.end(); ++it, ++uiAreaConfigurationRank) { |
| 560 | |
| 561 | if (*it == pAreaConfiguration) { |
| 562 | |
| 563 | return uiAreaConfigurationRank; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | assert(0); |
| 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | // Find area configuration from regular list based on rank: for ordered list maintainance |
| 573 | CAreaConfiguration* CDomainConfiguration::getAreaConfiguration(uint32_t uiAreaConfigurationRank) const |
| 574 | { |
| 575 | AreaConfigurationListIterator it; |
| 576 | uint32_t uiCurrentAreaConfigurationRank; |
| 577 | |
| 578 | // Propagate request to areas |
| 579 | for (it = _areaConfigurationList.begin(), uiCurrentAreaConfigurationRank = 0; it != _areaConfigurationList.end(); ++it, ++uiCurrentAreaConfigurationRank) { |
| 580 | |
| 581 | if (uiCurrentAreaConfigurationRank == uiAreaConfigurationRank) { |
| 582 | |
| 583 | return *it; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | assert(0); |
| 588 | |
| 589 | return NULL; |
| 590 | } |
| 591 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 592 | // Rule |
| 593 | const CCompoundRule* CDomainConfiguration::getRule() const |
| 594 | { |
| 595 | if (getNbChildren()) { |
| 596 | // Rule created |
| 597 | return static_cast<const CCompoundRule*>(getChild(ECompoundRule)); |
| 598 | } |
| 599 | return NULL; |
| 600 | } |
| 601 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 602 | CCompoundRule* CDomainConfiguration::getRule() |
| 603 | { |
| 604 | if (getNbChildren()) { |
| 605 | // Rule created |
| 606 | return static_cast<CCompoundRule*>(getChild(ECompoundRule)); |
| 607 | } |
| 608 | return NULL; |
| 609 | } |
| 610 | |
| 611 | void CDomainConfiguration::setRule(CCompoundRule* pRule) |
| 612 | { |
| 613 | CCompoundRule* pOldRule = getRule(); |
| 614 | |
| 615 | if (pOldRule) { |
| 616 | // Remove previous rule |
| 617 | removeChild(pOldRule); |
| 618 | |
| 619 | delete pOldRule; |
| 620 | } |
| 621 | |
| 622 | // Set new one |
| 623 | if (pRule) { |
| 624 | // Chain |
| 625 | addChild(pRule); |
| 626 | } |
| 627 | } |
| 628 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 629 | // Serialization |
| 630 | void CDomainConfiguration::binarySerialize(CBinaryStream& binaryStream) |
| 631 | { |
| 632 | AreaConfigurationListIterator it; |
| 633 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 634 | // Area configurations order |
| 635 | if (binaryStream.isOut()) { |
| 636 | |
| 637 | for (it = _orderedAreaConfigurationList.begin(); it != _orderedAreaConfigurationList.end(); ++it) { |
| 638 | |
| 639 | // Get rank |
| 640 | uint32_t uiAreaConfigurationRank = getAreaConfigurationRank(*it); |
| 641 | |
| 642 | // Store it |
| 643 | binaryStream.write((const uint8_t*)&uiAreaConfigurationRank, sizeof(uiAreaConfigurationRank)); |
| 644 | } |
| 645 | } else { |
| 646 | |
| 647 | // Empty ordered list first |
| 648 | _orderedAreaConfigurationList.resize(0); |
| 649 | |
| 650 | uint32_t uiAreaConfiguration; |
| 651 | |
| 652 | for (uiAreaConfiguration = 0; uiAreaConfiguration < _areaConfigurationList.size(); uiAreaConfiguration++) { |
| 653 | |
| 654 | // Get rank |
| 655 | uint32_t uiAreaConfigurationRank; |
| 656 | |
| 657 | binaryStream.read((uint8_t*)&uiAreaConfigurationRank, sizeof(uiAreaConfigurationRank)); |
| 658 | |
| 659 | _orderedAreaConfigurationList.push_back(getAreaConfiguration(uiAreaConfigurationRank)); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | // Propagate to areas |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 664 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 665 | |
| 666 | CAreaConfiguration* pAreaConfiguration = *it; |
| 667 | |
| 668 | pAreaConfiguration->serialize(binaryStream); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | // Data size |
| 673 | uint32_t CDomainConfiguration::getDataSize() const |
| 674 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 675 | uint32_t uiDataSize; |
| 676 | |
| 677 | // Add necessary size to store area configurations order |
| 678 | uiDataSize = _areaConfigurationList.size() * sizeof(uint32_t); |
| 679 | |
| 680 | // Propagate request to areas |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 681 | AreaConfigurationListIterator it; |
| 682 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 683 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 684 | |
| 685 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 686 | |
| 687 | uiDataSize += pAreaConfiguration->getSize(); |
| 688 | } |
| 689 | return uiDataSize; |
| 690 | } |