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 "Subsystem.h" |
| 32 | #include "ComponentLibrary.h" |
| 33 | #include "InstanceDefinition.h" |
| 34 | #include "XmlParameterSerializingContext.h" |
| 35 | #include "ParameterAccessContext.h" |
| 36 | #include "ConfigurationAccessContext.h" |
| 37 | #include "SubsystemObjectCreator.h" |
| 38 | #include <assert.h> |
| 39 | |
| 40 | #define base CConfigurableElement |
| 41 | |
| 42 | CSubsystem::CSubsystem(const string& strName) : base(strName), _pComponentLibrary(new CComponentLibrary), _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false) |
| 43 | { |
| 44 | // Note: A subsystem contains instance components |
| 45 | // InstanceDefintion and ComponentLibrary objects are then not chosen to be children |
| 46 | // They'll be delt with locally |
| 47 | } |
| 48 | |
| 49 | CSubsystem::~CSubsystem() |
| 50 | { |
| 51 | // Remove subsystem objects |
| 52 | SubsystemObjectListIterator subsystemObjectIt; |
| 53 | |
| 54 | for (subsystemObjectIt = _subsystemObjectList.begin(); subsystemObjectIt != _subsystemObjectList.end(); ++subsystemObjectIt) { |
| 55 | |
| 56 | delete *subsystemObjectIt; |
| 57 | } |
| 58 | |
| 59 | // Remove susbsystem creators |
| 60 | uint32_t uiIndex; |
| 61 | |
| 62 | for (uiIndex = 0; uiIndex < _subsystemObjectCreatorArray.size(); uiIndex++) { |
| 63 | |
| 64 | delete _subsystemObjectCreatorArray[uiIndex]; |
| 65 | } |
| 66 | |
| 67 | // Order matters! |
| 68 | delete _pInstanceDefinition; |
| 69 | delete _pComponentLibrary; |
| 70 | } |
| 71 | |
| 72 | string CSubsystem::getKind() const |
| 73 | { |
| 74 | return "Subsystem"; |
| 75 | } |
| 76 | |
| 77 | // Susbsystem Endianness |
| 78 | bool CSubsystem::isBigEndian() const |
| 79 | { |
| 80 | return _bBigEndian; |
| 81 | } |
| 82 | |
| 83 | // From IXmlSink |
| 84 | bool CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) |
| 85 | { |
| 86 | // Context |
| 87 | CXmlParameterSerializingContext& parameterBuildContext = static_cast<CXmlParameterSerializingContext&>(serializingContext); |
| 88 | |
| 89 | // Install temporary component library for further component creation |
| 90 | parameterBuildContext.setComponentLibrary(_pComponentLibrary); |
| 91 | |
| 92 | CXmlElement childElement; |
| 93 | |
| 94 | // XML populate ComponentLibrary |
| 95 | xmlElement.getChildElement("ComponentLibrary", childElement); |
| 96 | |
| 97 | if (!_pComponentLibrary->fromXml(childElement, serializingContext)) { |
| 98 | |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | // XML populate InstanceDefintion |
| 103 | xmlElement.getChildElement("InstanceDefintion", childElement); |
| 104 | if (!_pInstanceDefinition->fromXml(childElement, serializingContext)) { |
| 105 | |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | // Create components |
| 110 | _pInstanceDefinition->createInstances(this); |
| 111 | |
| 112 | // Execute mapping to create subsystem mapping entities |
| 113 | string strError; |
| 114 | if (!mapSubsystemElements(strError)) { |
| 115 | |
| 116 | serializingContext.setError(strError); |
| 117 | |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | // Endianness |
| 122 | _bBigEndian = xmlElement.getAttributeBoolean("Endianness", "Big"); |
| 123 | |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | // XML configuration settings parsing |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 128 | bool CSubsystem::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 129 | { |
| 130 | // Fix Endianness |
| 131 | configurationAccessContext.setBigEndianSubsystem(_bBigEndian); |
| 132 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 133 | return base::serializeXmlSettings(xmlConfigurationSettingsElementContent, configurationAccessContext); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
| 137 | bool CSubsystem::mapSubsystemElements(string& strError) |
| 138 | { |
| 139 | // Default mapping context |
| 140 | _contextStack.push(CMappingContext(_contextMappingKeyArray.size())); |
| 141 | |
| 142 | // Map all instantiated subelements in subsystem |
| 143 | uint32_t uiNbChildren = getNbChildren(); |
| 144 | uint32_t uiChild; |
| 145 | |
| 146 | for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { |
| 147 | |
| 148 | CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); |
| 149 | |
| 150 | if (!pInstanceConfigurableChildElement->map(*this, strError)) { |
| 151 | |
| 152 | return false; |
| 153 | } |
| 154 | } |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | // Parameter access |
| 159 | bool CSubsystem::setValue(CPathNavigator& pathNavigator, const string& strValue, CErrorContext& errorContext) const |
| 160 | { |
| 161 | CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); |
| 162 | |
| 163 | // Deal with Endianness |
| 164 | parameterContext.setBigEndianSubsystem(_bBigEndian); |
| 165 | |
| 166 | return base::setValue(pathNavigator, strValue, errorContext); |
| 167 | } |
| 168 | |
| 169 | bool CSubsystem::getValue(CPathNavigator& pathNavigator, string& strValue, CErrorContext& errorContext) const |
| 170 | { |
| 171 | CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); |
| 172 | |
| 173 | // Deal with Endianness |
| 174 | parameterContext.setBigEndianSubsystem(_bBigEndian); |
| 175 | |
| 176 | return base::getValue(pathNavigator, strValue, errorContext); |
| 177 | } |
| 178 | |
| 179 | void CSubsystem::logValue(string& strValue, CErrorContext& errorContext) const |
| 180 | { |
| 181 | CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); |
| 182 | |
| 183 | // Deal with Endianness |
| 184 | parameterContext.setBigEndianSubsystem(_bBigEndian); |
| 185 | |
| 186 | return base::logValue(strValue, errorContext); |
| 187 | } |
| 188 | |
| 189 | // Used for simulation only |
| 190 | void CSubsystem::setDefaultValues(CParameterAccessContext& parameterAccessContext) const |
| 191 | { |
| 192 | // Deal with Endianness |
| 193 | parameterAccessContext.setBigEndianSubsystem(_bBigEndian); |
| 194 | |
| 195 | base::setDefaultValues(parameterAccessContext); |
| 196 | } |
| 197 | |
| 198 | // Belonging subsystem |
| 199 | const CSubsystem* CSubsystem::getBelongingSubsystem() const |
| 200 | { |
| 201 | return this; |
| 202 | } |
| 203 | |
| 204 | // Subsystem context mapping keys publication |
| 205 | void CSubsystem::addContextMappingKey(const string& strMappingKey) |
| 206 | { |
| 207 | _contextMappingKeyArray.push_back(strMappingKey); |
| 208 | } |
| 209 | |
| 210 | // Subsystem object creator publication (strong reference) |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 211 | void CSubsystem::addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 212 | { |
| 213 | _subsystemObjectCreatorArray.push_back(pSubsystemObjectCreator); |
| 214 | } |
| 215 | |
| 216 | // Mapping generic context handling |
| 217 | bool CSubsystem::handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError) |
| 218 | { |
| 219 | // Feed context with found mapping data |
| 220 | uint32_t uiItem; |
| 221 | |
| 222 | for (uiItem = 0; uiItem < _contextMappingKeyArray.size(); uiItem++) { |
| 223 | |
| 224 | string strKey = _contextMappingKeyArray[uiItem]; |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 225 | const string* pStrValue; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 226 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 227 | if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 228 | // Assign item to context |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 229 | if (!context.setItem(uiItem, pStrValue)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 230 | |
| 231 | getMappingError(strError, strKey, "Already set", pInstanceConfigurableElement); |
| 232 | |
| 233 | return false; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | // Creation handling |
| 241 | bool CSubsystem::handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError) |
| 242 | { |
| 243 | uint32_t uiItem; |
| 244 | |
| 245 | for (uiItem = 0; uiItem < _subsystemObjectCreatorArray.size(); uiItem++) { |
| 246 | |
| 247 | const CSubsystemObjectCreator* pSubsystemObjectCreator = _subsystemObjectCreatorArray[uiItem]; |
| 248 | |
| 249 | // Mapping key |
| 250 | string strKey = pSubsystemObjectCreator->getMappingKey(); |
| 251 | // Object id |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 252 | const string* pStrValue; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 253 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 254 | if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 255 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 256 | // First check context consistensy (required ancestors must have been set prior to object creation) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 257 | uint32_t uiAncestorKey; |
| 258 | uint32_t uiAncestorMask = pSubsystemObjectCreator->getAncestorMask(); |
| 259 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 260 | for (uiAncestorKey = 0; uiAncestorKey < _contextMappingKeyArray.size(); uiAncestorKey++) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 261 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 262 | if (!((1 << uiAncestorKey) & uiAncestorMask)) { |
| 263 | // Ancestor not required |
| 264 | continue; |
| 265 | } |
| 266 | // Check ancestor was provided |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 267 | if (!context.iSet(uiAncestorKey)) { |
| 268 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 269 | getMappingError(strError, strKey, _contextMappingKeyArray[uiAncestorKey] + " not set", pInstanceConfigurableElement); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 270 | |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 275 | // Then check configurable element size is correct |
| 276 | if (pInstanceConfigurableElement->getFootPrint() > pSubsystemObjectCreator->getMaxConfigurableElementSize()) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 277 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 278 | string strSizeError = "Size should not exceed " + pInstanceConfigurableElement->getFootprintAsString(); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 279 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 280 | getMappingError(strError, strKey, strSizeError, pInstanceConfigurableElement); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 281 | |
| 282 | return false; |
| 283 | } |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 284 | |
| 285 | // Do create object and keep its track |
| 286 | _subsystemObjectList.push_back(pSubsystemObjectCreator->objectCreate(*pStrValue, pInstanceConfigurableElement, context)); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 287 | |
| 288 | // Done |
| 289 | return true; |
| 290 | } |
| 291 | } |
| 292 | getMappingError(strError, "Mapping key", "Not found", pInstanceConfigurableElement); |
| 293 | |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | // Generic error handling from derived subsystem classes |
| 298 | void CSubsystem::getMappingError(string& strError, const string& strKey, const string& strMessage, const CInstanceConfigurableElement* pInstanceConfigurableElement) |
| 299 | { |
| 300 | strError = getName() + " " + getKind() + " mapping:\n" + strKey + " error : \"" + strMessage + "\" for element " + pInstanceConfigurableElement->getPath(); |
| 301 | } |
| 302 | |
| 303 | // From IMapper |
| 304 | bool CSubsystem::mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, string& strError) |
| 305 | { |
| 306 | // Get current context |
| 307 | CMappingContext context = _contextStack.top(); |
| 308 | |
| 309 | switch(pInstanceConfigurableElement->getType()) { |
| 310 | |
| 311 | case CInstanceConfigurableElement::EComponent: |
| 312 | |
| 313 | if (!handleMappingContext(pInstanceConfigurableElement, context, strError)) { |
| 314 | |
| 315 | return false; |
| 316 | } |
| 317 | break; |
| 318 | case CInstanceConfigurableElement::EParameterBlock: |
| 319 | case CInstanceConfigurableElement::EBitParameterBlock: |
| 320 | case CInstanceConfigurableElement::EParameter: |
| 321 | { |
| 322 | if (!handleSubsystemObjectCreation(pInstanceConfigurableElement, context, strError)) { |
| 323 | |
| 324 | return false; |
| 325 | } |
| 326 | break; |
| 327 | } |
| 328 | default: |
| 329 | assert(0); |
| 330 | return false; |
| 331 | } |
| 332 | |
| 333 | // Push context |
| 334 | _contextStack.push(context); |
| 335 | |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | void CSubsystem::mapEnd() |
| 340 | { |
| 341 | // Unstack context |
| 342 | _contextStack.pop(); |
| 343 | } |