| 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" |
| 35 | #include <assert.h> |
| 36 | |
| 37 | #define base CBinarySerializableElement |
| 38 | |
| 39 | CDomainConfiguration::CDomainConfiguration(const string& strName) : base(strName) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | CDomainConfiguration::~CDomainConfiguration() |
| 44 | { |
| 45 | AreaConfigurationListIterator it; |
| 46 | |
| 47 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 48 | |
| 49 | delete *it; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Class kind |
| 54 | string CDomainConfiguration::getKind() const |
| 55 | { |
| 56 | return "Configuration"; |
| 57 | } |
| 58 | |
| 59 | // Child dynamic creation |
| 60 | bool CDomainConfiguration::childrenAreDynamic() const |
| 61 | { |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | // XML configuration settings parsing |
| 66 | bool CDomainConfiguration::serializeXmlSettings(const CConfigurableElement* pConfigurableElement, CXmlElement& xmlConfigurationSettingsElement, CConfigurationAccessContext& configurationAccessContext) |
| 67 | { |
| 68 | // Find related AreaConfiguration |
| 69 | CAreaConfiguration* pAreaConfiguration = getAreaConfiguration(pConfigurableElement); |
| 70 | |
| 71 | assert(pAreaConfiguration); |
| 72 | |
| 73 | // Delegate to corresponding area configuration |
| 74 | return pAreaConfiguration->serializeXmlSettings(xmlConfigurationSettingsElement, configurationAccessContext); |
| 75 | } |
| 76 | |
| 77 | // Configurable Elements association |
| 78 | void CDomainConfiguration::addConfigurableElement(const CConfigurableElement* pConfigurableElement) |
| 79 | { |
| 80 | _areaConfigurationList.push_back(new CAreaConfiguration(pConfigurableElement)); |
| 81 | } |
| 82 | |
| 83 | void CDomainConfiguration::removeConfigurableElement(const CConfigurableElement* pConfigurableElement) |
| 84 | { |
| 85 | CAreaConfiguration* pAreaConfigurationToRemove = getAreaConfiguration(pConfigurableElement); |
| 86 | |
| 87 | _areaConfigurationList.remove(pAreaConfigurationToRemove); |
| 88 | |
| 89 | delete pAreaConfigurationToRemove; |
| 90 | } |
| 91 | |
| 92 | // Save data from current |
| 93 | void CDomainConfiguration::save(const CParameterBlackboard* pMainBlackboard) |
| 94 | { |
| 95 | AreaConfigurationListIterator it; |
| 96 | |
| 97 | // Just propagate to areas |
| 98 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 99 | |
| 100 | CAreaConfiguration* pAreaConfiguration = *it; |
| 101 | |
| 102 | pAreaConfiguration->save(pMainBlackboard); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Apply data to current |
| 107 | void CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard) const |
| 108 | { |
| 109 | AreaConfigurationListIterator it; |
| 110 | |
| 111 | // Just propagate to areas |
| 112 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 113 | |
| 114 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 115 | |
| 116 | pAreaConfiguration->restore(pMainBlackboard); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Ensure validity for configurable element area configuration |
| 121 | void CDomainConfiguration::validate(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) |
| 122 | { |
| 123 | CAreaConfiguration* pAreaConfigurationToValidate = getAreaConfiguration(pConfigurableElement); |
| 124 | |
| 125 | // Delegate |
| 126 | pAreaConfigurationToValidate->validate(pMainBlackboard); |
| 127 | } |
| 128 | |
| 129 | // Ensure validity of all area configurations |
| 130 | void CDomainConfiguration::validate(const CParameterBlackboard* pMainBlackboard) |
| 131 | { |
| 132 | AreaConfigurationListIterator it; |
| 133 | |
| 134 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 135 | |
| 136 | CAreaConfiguration* pAreaConfiguration = *it; |
| 137 | |
| 138 | pAreaConfiguration->validate(pMainBlackboard); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // Return configuration validity for given configurable element |
| 143 | bool CDomainConfiguration::isValid(const CConfigurableElement* pConfigurableElement) const |
| 144 | { |
| 145 | // Get child configurable elemnt's area configuration |
| 146 | CAreaConfiguration* pAreaConfiguration = getAreaConfiguration(pConfigurableElement); |
| 147 | |
| 148 | assert(pAreaConfiguration); |
| 149 | |
| 150 | return pAreaConfiguration->isValid(); |
| 151 | } |
| 152 | |
| 153 | // Ensure validity of configurable element's area configuration by copying in from a valid one |
| 154 | void CDomainConfiguration::validateAgainst(const CDomainConfiguration* pValidDomainConfiguration, const CConfigurableElement* pConfigurableElement) |
| 155 | { |
| 156 | // Retrieve related area configurations |
| 157 | CAreaConfiguration* pAreaConfigurationToValidate = getAreaConfiguration(pConfigurableElement); |
| 158 | const CAreaConfiguration* pAreaConfigurationToValidateAgainst = pValidDomainConfiguration->getAreaConfiguration(pConfigurableElement); |
| 159 | |
| 160 | // Delegate to area |
| 161 | pAreaConfigurationToValidate->validateAgainst(pAreaConfigurationToValidateAgainst); |
| 162 | } |
| 163 | |
| 164 | // Ensure validity of all configurable element's area configuration by copying in from a valid ones |
| 165 | void CDomainConfiguration::validateAgainst(const CDomainConfiguration* pValidDomainConfiguration) |
| 166 | { |
| 167 | // Copy in configuration data from against domain |
| 168 | AreaConfigurationListIterator it, itAgainst; |
| 169 | |
| 170 | for (it = _areaConfigurationList.begin(), itAgainst = pValidDomainConfiguration->_areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it, ++itAgainst) { |
| 171 | |
| 172 | CAreaConfiguration* pAreaConfigurationToValidate = *it; |
| 173 | const CAreaConfiguration* pAreaConfigurationToValidateAgainst = *itAgainst; |
| 174 | |
| 175 | // Delegate to area |
| 176 | pAreaConfigurationToValidate->validateAgainst(pAreaConfigurationToValidateAgainst); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // Dynamic data application |
| 181 | bool CDomainConfiguration::isApplicable() const |
| 182 | { |
| 183 | const CCompoundRule* pRule = getRule(); |
| 184 | |
| 185 | return pRule && pRule->matches(); |
| 186 | } |
| 187 | |
| 188 | // Merge existing configurations to given configurable element ones |
| 189 | void CDomainConfiguration::merge(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement) |
| 190 | { |
| 191 | // Retrieve related area configurations |
| 192 | CAreaConfiguration* pAreaConfigurationToMergeTo = getAreaConfiguration(pToConfigurableElement); |
| 193 | const CAreaConfiguration* pAreaConfigurationToMergeFrom = getAreaConfiguration(pFromConfigurableElement); |
| 194 | |
| 195 | // Do the merge |
| 196 | pAreaConfigurationToMergeTo->copyFromInner(pAreaConfigurationToMergeFrom); |
| 197 | } |
| 198 | |
| 199 | // Domain splitting |
| 200 | void CDomainConfiguration::split(CConfigurableElement* pFromConfigurableElement) |
| 201 | { |
| 202 | // Retrieve related area configuration |
| 203 | const CAreaConfiguration* pAreaConfigurationToSplitFrom = getAreaConfiguration(pFromConfigurableElement); |
| 204 | |
| 205 | // Go through children areas to copy configuration data to them |
| 206 | uint32_t uiNbConfigurableElementChildren = pFromConfigurableElement->getNbChildren(); |
| 207 | uint32_t uiChild; |
| 208 | |
| 209 | for (uiChild = 0; uiChild < uiNbConfigurableElementChildren; uiChild++) { |
| 210 | |
| 211 | CConfigurableElement* pToChildConfigurableElement = static_cast<CConfigurableElement*>(pFromConfigurableElement->getChild(uiChild)); |
| 212 | |
| 213 | // Get child configurable elemnt's area configuration |
| 214 | CAreaConfiguration* pChildAreaConfiguration = getAreaConfiguration(pToChildConfigurableElement); |
| 215 | |
| 216 | // Do the copy |
| 217 | pAreaConfigurationToSplitFrom->copyToInner(pChildAreaConfiguration); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // AreaConfiguration retrieval from configurable element |
| 222 | CAreaConfiguration* CDomainConfiguration::getAreaConfiguration(const CConfigurableElement* pConfigurableElement) const |
| 223 | { |
| 224 | AreaConfigurationListIterator it; |
| 225 | |
| 226 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 227 | |
| 228 | CAreaConfiguration* pAreaConfiguration = *it; |
| 229 | |
| 230 | if (pAreaConfiguration->getConfigurableElement() == pConfigurableElement) { |
| 231 | |
| 232 | return pAreaConfiguration; |
| 233 | } |
| 234 | } |
| 235 | // Not found? |
| 236 | assert(0); |
| 237 | |
| 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | // Presence of application condition |
| 242 | bool CDomainConfiguration::hasRule() const |
| 243 | { |
| 244 | return !!getRule(); |
| 245 | } |
| 246 | |
| 247 | // Rule |
| 248 | const CCompoundRule* CDomainConfiguration::getRule() const |
| 249 | { |
| 250 | if (getNbChildren()) { |
| 251 | // Rule created |
| 252 | return static_cast<const CCompoundRule*>(getChild(ECompoundRule)); |
| 253 | } |
| 254 | return NULL; |
| 255 | } |
| 256 | |
| 257 | // Serialization |
| 258 | void CDomainConfiguration::binarySerialize(CBinaryStream& binaryStream) |
| 259 | { |
| 260 | AreaConfigurationListIterator it; |
| 261 | |
| 262 | // Just propagate to areas |
| 263 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 264 | |
| 265 | CAreaConfiguration* pAreaConfiguration = *it; |
| 266 | |
| 267 | pAreaConfiguration->serialize(binaryStream); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Data size |
| 272 | uint32_t CDomainConfiguration::getDataSize() const |
| 273 | { |
| 274 | uint32_t uiDataSize = 0; |
| 275 | AreaConfigurationListIterator it; |
| 276 | |
| 277 | // Just propagate request to areas |
| 278 | for (it = _areaConfigurationList.begin(); it != _areaConfigurationList.end(); ++it) { |
| 279 | |
| 280 | const CAreaConfiguration* pAreaConfiguration = *it; |
| 281 | |
| 282 | uiDataSize += pAreaConfiguration->getSize(); |
| 283 | } |
| 284 | return uiDataSize; |
| 285 | } |