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