| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1 | /* <auto_header> |
| 2 | * <FILENAME> |
| 3 | * |
| 4 | * INTEL CONFIDENTIAL |
| 5 | * Copyright © 2011 Intel |
| 6 | * Corporation All Rights Reserved. |
| 7 | * |
| 8 | * The source code contained or described herein and all documents related to |
| 9 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 10 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 11 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 12 | * and confidential information of Intel or its suppliers and licensors. The |
| 13 | * Material is protected by worldwide copyright and trade secret laws and |
| 14 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 15 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 16 | * disclosed in any way without Intel’s prior express written permission. |
| 17 | * |
| 18 | * No license under any patent, copyright, trade secret or other intellectual |
| 19 | * property right is granted to or conferred upon you by disclosure or delivery |
| 20 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 21 | * otherwise. Any license under such intellectual property rights must be |
| 22 | * express and approved by Intel in writing. |
| 23 | * |
| 24 | * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) |
| 25 | * CREATED: 2011-06-01 |
| 26 | * UPDATED: 2011-07-27 |
| 27 | * |
| 28 | * |
| 29 | * </auto_header> |
| 30 | */ |
| 31 | #include "DomainConfiguration.h" |
| 32 | #include "AreaConfiguration.h" |
| 33 | #include "ConfigurableElement.h" |
| 34 | #include "CompoundRule.h" |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 35 | #include "Subsystem.h" |
| 36 | #include "XmlDomainSerializingContext.h" |
| 37 | #include "ConfigurationAccessContext.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 38 | #include <assert.h> |
| 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 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 214 | CAreaConfiguration* pAreaConfiguration = new CAreaConfiguration(pConfigurableElement, pSyncerSet); |
| 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 | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 285 | // Save data from current |
| 286 | void CDomainConfiguration::save(const CParameterBlackboard* pMainBlackboard) |
| 287 | { |
| 288 | AreaConfigurationListIterator it; |
| 289 | |
| 290 | // Just propagate to areas |
| 291 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 292 | |
| 293 | CAreaConfiguration* pAreaConfiguration = *it; |
| 294 | |
| 295 | pAreaConfiguration->save(pMainBlackboard); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // Apply data to current |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 300 | bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool bSync, string& strError) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 301 | { |
| 302 | AreaConfigurationListIterator it; |
| 303 | |
| 304 | // Just propagate to areas |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 305 | for (it = _orderedAreaConfigurationList.begin(); it != _orderedAreaConfigurationList.end(); ++it) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 306 | |
| 307 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 308 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 309 | if (!pAreaConfiguration->restore(pMainBlackboard, bSync, strError)) { |
| 310 | |
| 311 | return false; |
| 312 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 313 | } |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 314 | |
| 315 | return true; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | // Ensure validity for configurable element area configuration |
| 319 | void CDomainConfiguration::validate(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) |
| 320 | { |
| 321 | CAreaConfiguration* pAreaConfigurationToValidate = getAreaConfiguration(pConfigurableElement); |
| 322 | |
| 323 | // Delegate |
| 324 | pAreaConfigurationToValidate->validate(pMainBlackboard); |
| 325 | } |
| 326 | |
| 327 | // Ensure validity of all area configurations |
| 328 | void CDomainConfiguration::validate(const CParameterBlackboard* pMainBlackboard) |
| 329 | { |
| 330 | AreaConfigurationListIterator it; |
| 331 | |
| 332 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 333 | |
| 334 | CAreaConfiguration* pAreaConfiguration = *it; |
| 335 | |
| 336 | pAreaConfiguration->validate(pMainBlackboard); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // Return configuration validity for given configurable element |
| 341 | bool CDomainConfiguration::isValid(const CConfigurableElement* pConfigurableElement) const |
| 342 | { |
| 343 | // Get child configurable elemnt's area configuration |
| 344 | CAreaConfiguration* pAreaConfiguration = getAreaConfiguration(pConfigurableElement); |
| 345 | |
| 346 | assert(pAreaConfiguration); |
| 347 | |
| 348 | return pAreaConfiguration->isValid(); |
| 349 | } |
| 350 | |
| 351 | // Ensure validity of configurable element's area configuration by copying in from a valid one |
| 352 | void CDomainConfiguration::validateAgainst(const CDomainConfiguration* pValidDomainConfiguration, const CConfigurableElement* pConfigurableElement) |
| 353 | { |
| 354 | // Retrieve related area configurations |
| 355 | CAreaConfiguration* pAreaConfigurationToValidate = getAreaConfiguration(pConfigurableElement); |
| 356 | const CAreaConfiguration* pAreaConfigurationToValidateAgainst = pValidDomainConfiguration->getAreaConfiguration(pConfigurableElement); |
| 357 | |
| 358 | // Delegate to area |
| 359 | pAreaConfigurationToValidate->validateAgainst(pAreaConfigurationToValidateAgainst); |
| 360 | } |
| 361 | |
| 362 | // Ensure validity of all configurable element's area configuration by copying in from a valid ones |
| 363 | void CDomainConfiguration::validateAgainst(const CDomainConfiguration* pValidDomainConfiguration) |
| 364 | { |
| 365 | // Copy in configuration data from against domain |
| 366 | AreaConfigurationListIterator it, itAgainst; |
| 367 | |
| 368 | for (it = _areaConfigurationList.begin(), itAgainst = pValidDomainConfiguration->_areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it, ++itAgainst) { |
| 369 | |
| 370 | CAreaConfiguration* pAreaConfigurationToValidate = *it; |
| 371 | const CAreaConfiguration* pAreaConfigurationToValidateAgainst = *itAgainst; |
| 372 | |
| 373 | // Delegate to area |
| 374 | pAreaConfigurationToValidate->validateAgainst(pAreaConfigurationToValidateAgainst); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // Dynamic data application |
| 379 | bool CDomainConfiguration::isApplicable() const |
| 380 | { |
| 381 | const CCompoundRule* pRule = getRule(); |
| 382 | |
| 383 | return pRule && pRule->matches(); |
| 384 | } |
| 385 | |
| 386 | // Merge existing configurations to given configurable element ones |
| 387 | void CDomainConfiguration::merge(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement) |
| 388 | { |
| 389 | // Retrieve related area configurations |
| 390 | CAreaConfiguration* pAreaConfigurationToMergeTo = getAreaConfiguration(pToConfigurableElement); |
| 391 | const CAreaConfiguration* pAreaConfigurationToMergeFrom = getAreaConfiguration(pFromConfigurableElement); |
| 392 | |
| 393 | // Do the merge |
| 394 | pAreaConfigurationToMergeTo->copyFromInner(pAreaConfigurationToMergeFrom); |
| 395 | } |
| 396 | |
| 397 | // Domain splitting |
| 398 | void CDomainConfiguration::split(CConfigurableElement* pFromConfigurableElement) |
| 399 | { |
| 400 | // Retrieve related area configuration |
| 401 | const CAreaConfiguration* pAreaConfigurationToSplitFrom = getAreaConfiguration(pFromConfigurableElement); |
| 402 | |
| 403 | // Go through children areas to copy configuration data to them |
| 404 | uint32_t uiNbConfigurableElementChildren = pFromConfigurableElement->getNbChildren(); |
| 405 | uint32_t uiChild; |
| 406 | |
| 407 | for (uiChild = 0; uiChild < uiNbConfigurableElementChildren; uiChild++) { |
| 408 | |
| 409 | CConfigurableElement* pToChildConfigurableElement = static_cast<CConfigurableElement*>(pFromConfigurableElement->getChild(uiChild)); |
| 410 | |
| 411 | // Get child configurable elemnt's area configuration |
| 412 | CAreaConfiguration* pChildAreaConfiguration = getAreaConfiguration(pToChildConfigurableElement); |
| 413 | |
| 414 | // Do the copy |
| 415 | pAreaConfigurationToSplitFrom->copyToInner(pChildAreaConfiguration); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | // AreaConfiguration retrieval from configurable element |
| 420 | CAreaConfiguration* CDomainConfiguration::getAreaConfiguration(const CConfigurableElement* pConfigurableElement) const |
| 421 | { |
| 422 | AreaConfigurationListIterator it; |
| 423 | |
| 424 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 425 | |
| 426 | CAreaConfiguration* pAreaConfiguration = *it; |
| 427 | |
| 428 | if (pAreaConfiguration->getConfigurableElement() == pConfigurableElement) { |
| 429 | |
| 430 | return pAreaConfiguration; |
| 431 | } |
| 432 | } |
| 433 | // Not found? |
| 434 | assert(0); |
| 435 | |
| 436 | return NULL; |
| 437 | } |
| 438 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 439 | // AreaConfiguration retrieval from present area configurations |
| 440 | CAreaConfiguration* CDomainConfiguration::findAreaConfiguration(const string& strConfigurableElementPath) const |
| 441 | { |
| Patrick Benavoli | 4bed921 | 2011-10-27 14:18:00 +0200 | [diff] [blame^] | 442 | return findAreaConfiguration(strConfigurableElementPath, _areaConfigurationList); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | // AreaConfiguration retrieval from given area configuration list |
| 446 | CAreaConfiguration* CDomainConfiguration::findAreaConfiguration(const string& strConfigurableElementPath, const list<CAreaConfiguration*>& areaConfigurationList) const |
| 447 | { |
| 448 | AreaConfigurationListIterator it; |
| 449 | |
| 450 | for (it = areaConfigurationList.begin(); it != areaConfigurationList.end(); ++it) { |
| 451 | |
| 452 | CAreaConfiguration* pAreaConfiguration = *it; |
| 453 | |
| 454 | if (pAreaConfiguration->getConfigurableElement()->getPath() == strConfigurableElementPath) { |
| 455 | |
| 456 | return pAreaConfiguration; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // Not found |
| 461 | return NULL; |
| 462 | } |
| 463 | |
| 464 | // Area configuration ordering |
| 465 | void CDomainConfiguration::reorderAreaConfigurations(const list<CAreaConfiguration*>& areaConfigurationList) |
| 466 | { |
| 467 | // Ensure elements in provided list appear first and ordered the same way in internal one |
| 468 | |
| 469 | // Remove all elements present in the provided list from the internal one |
| 470 | AreaConfigurationListIterator it; |
| 471 | |
| 472 | for (it = areaConfigurationList.begin(); it != areaConfigurationList.end(); ++it) { |
| 473 | |
| 474 | _orderedAreaConfigurationList.remove(*it); |
| 475 | } |
| 476 | |
| 477 | // Prepended provided elements into internal list |
| 478 | _orderedAreaConfigurationList.insert(_orderedAreaConfigurationList.begin(), areaConfigurationList.begin(), areaConfigurationList.end()); |
| 479 | } |
| 480 | |
| 481 | // Find area configuration rank from regular list: for ordered list maintainance |
| 482 | uint32_t CDomainConfiguration::getAreaConfigurationRank(const CAreaConfiguration* pAreaConfiguration) const |
| 483 | { |
| 484 | uint32_t uiAreaConfigurationRank; |
| 485 | AreaConfigurationListIterator it; |
| 486 | |
| 487 | // Propagate request to areas |
| 488 | for (it = _areaConfigurationList.begin(), uiAreaConfigurationRank = 0; it != _areaConfigurationList.end(); ++it, ++uiAreaConfigurationRank) { |
| 489 | |
| 490 | if (*it == pAreaConfiguration) { |
| 491 | |
| 492 | return uiAreaConfigurationRank; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | assert(0); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | // Find area configuration from regular list based on rank: for ordered list maintainance |
| 502 | CAreaConfiguration* CDomainConfiguration::getAreaConfiguration(uint32_t uiAreaConfigurationRank) const |
| 503 | { |
| 504 | AreaConfigurationListIterator it; |
| 505 | uint32_t uiCurrentAreaConfigurationRank; |
| 506 | |
| 507 | // Propagate request to areas |
| 508 | for (it = _areaConfigurationList.begin(), uiCurrentAreaConfigurationRank = 0; it != _areaConfigurationList.end(); ++it, ++uiCurrentAreaConfigurationRank) { |
| 509 | |
| 510 | if (uiCurrentAreaConfigurationRank == uiAreaConfigurationRank) { |
| 511 | |
| 512 | return *it; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | assert(0); |
| 517 | |
| 518 | return NULL; |
| 519 | } |
| 520 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 521 | // Presence of application condition |
| 522 | bool CDomainConfiguration::hasRule() const |
| 523 | { |
| 524 | return !!getRule(); |
| 525 | } |
| 526 | |
| 527 | // Rule |
| 528 | const CCompoundRule* CDomainConfiguration::getRule() const |
| 529 | { |
| 530 | if (getNbChildren()) { |
| 531 | // Rule created |
| 532 | return static_cast<const CCompoundRule*>(getChild(ECompoundRule)); |
| 533 | } |
| 534 | return NULL; |
| 535 | } |
| 536 | |
| 537 | // Serialization |
| 538 | void CDomainConfiguration::binarySerialize(CBinaryStream& binaryStream) |
| 539 | { |
| 540 | AreaConfigurationListIterator it; |
| 541 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 542 | // Area configurations order |
| 543 | if (binaryStream.isOut()) { |
| 544 | |
| 545 | for (it = _orderedAreaConfigurationList.begin(); it != _orderedAreaConfigurationList.end(); ++it) { |
| 546 | |
| 547 | // Get rank |
| 548 | uint32_t uiAreaConfigurationRank = getAreaConfigurationRank(*it); |
| 549 | |
| 550 | // Store it |
| 551 | binaryStream.write((const uint8_t*)&uiAreaConfigurationRank, sizeof(uiAreaConfigurationRank)); |
| 552 | } |
| 553 | } else { |
| 554 | |
| 555 | // Empty ordered list first |
| 556 | _orderedAreaConfigurationList.resize(0); |
| 557 | |
| 558 | uint32_t uiAreaConfiguration; |
| 559 | |
| 560 | for (uiAreaConfiguration = 0; uiAreaConfiguration < _areaConfigurationList.size(); uiAreaConfiguration++) { |
| 561 | |
| 562 | // Get rank |
| 563 | uint32_t uiAreaConfigurationRank; |
| 564 | |
| 565 | binaryStream.read((uint8_t*)&uiAreaConfigurationRank, sizeof(uiAreaConfigurationRank)); |
| 566 | |
| 567 | _orderedAreaConfigurationList.push_back(getAreaConfiguration(uiAreaConfigurationRank)); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | // Propagate to areas |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 572 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 573 | |
| 574 | CAreaConfiguration* pAreaConfiguration = *it; |
| 575 | |
| 576 | pAreaConfiguration->serialize(binaryStream); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // Data size |
| 581 | uint32_t CDomainConfiguration::getDataSize() const |
| 582 | { |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 583 | uint32_t uiDataSize; |
| 584 | |
| 585 | // Add necessary size to store area configurations order |
| 586 | uiDataSize = _areaConfigurationList.size() * sizeof(uint32_t); |
| 587 | |
| 588 | // Propagate request to areas |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 589 | AreaConfigurationListIterator it; |
| 590 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 591 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 592 | |
| 593 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 594 | |
| 595 | uiDataSize += pAreaConfiguration->getSize(); |
| 596 | } |
| 597 | return uiDataSize; |
| 598 | } |