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 |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 159 | bool CSubsystem::setValue(CPathNavigator& pathNavigator, const string& strValue, CParameterAccessContext& parameterContext) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 160 | { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 161 | // Deal with Endianness |
| 162 | parameterContext.setBigEndianSubsystem(_bBigEndian); |
| 163 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 164 | return base::setValue(pathNavigator, strValue, parameterContext); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 167 | bool CSubsystem::getValue(CPathNavigator& pathNavigator, string& strValue, CParameterAccessContext& parameterContext) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 168 | { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 169 | // Deal with Endianness |
| 170 | parameterContext.setBigEndianSubsystem(_bBigEndian); |
| 171 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 172 | return base::getValue(pathNavigator, strValue, parameterContext); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | void CSubsystem::logValue(string& strValue, CErrorContext& errorContext) const |
| 176 | { |
| 177 | CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext); |
| 178 | |
| 179 | // Deal with Endianness |
| 180 | parameterContext.setBigEndianSubsystem(_bBigEndian); |
| 181 | |
| 182 | return base::logValue(strValue, errorContext); |
| 183 | } |
| 184 | |
| 185 | // Used for simulation only |
| 186 | void CSubsystem::setDefaultValues(CParameterAccessContext& parameterAccessContext) const |
| 187 | { |
| 188 | // Deal with Endianness |
| 189 | parameterAccessContext.setBigEndianSubsystem(_bBigEndian); |
| 190 | |
| 191 | base::setDefaultValues(parameterAccessContext); |
| 192 | } |
| 193 | |
| 194 | // Belonging subsystem |
| 195 | const CSubsystem* CSubsystem::getBelongingSubsystem() const |
| 196 | { |
| 197 | return this; |
| 198 | } |
| 199 | |
| 200 | // Subsystem context mapping keys publication |
| 201 | void CSubsystem::addContextMappingKey(const string& strMappingKey) |
| 202 | { |
| 203 | _contextMappingKeyArray.push_back(strMappingKey); |
| 204 | } |
| 205 | |
| 206 | // Subsystem object creator publication (strong reference) |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 207 | void CSubsystem::addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 208 | { |
| 209 | _subsystemObjectCreatorArray.push_back(pSubsystemObjectCreator); |
| 210 | } |
| 211 | |
| 212 | // Mapping generic context handling |
| 213 | bool CSubsystem::handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError) |
| 214 | { |
| 215 | // Feed context with found mapping data |
| 216 | uint32_t uiItem; |
| 217 | |
| 218 | for (uiItem = 0; uiItem < _contextMappingKeyArray.size(); uiItem++) { |
| 219 | |
| 220 | string strKey = _contextMappingKeyArray[uiItem]; |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 221 | const string* pStrValue; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 222 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 223 | if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 224 | // Assign item to context |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 225 | if (!context.setItem(uiItem, pStrValue)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 226 | |
| 227 | getMappingError(strError, strKey, "Already set", pInstanceConfigurableElement); |
| 228 | |
| 229 | return false; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | return true; |
| 234 | } |
| 235 | |
| 236 | // Creation handling |
| 237 | bool CSubsystem::handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError) |
| 238 | { |
| 239 | uint32_t uiItem; |
| 240 | |
| 241 | for (uiItem = 0; uiItem < _subsystemObjectCreatorArray.size(); uiItem++) { |
| 242 | |
| 243 | const CSubsystemObjectCreator* pSubsystemObjectCreator = _subsystemObjectCreatorArray[uiItem]; |
| 244 | |
| 245 | // Mapping key |
| 246 | string strKey = pSubsystemObjectCreator->getMappingKey(); |
| 247 | // Object id |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 248 | const string* pStrValue; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 249 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 250 | if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 251 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 252 | // 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] | 253 | uint32_t uiAncestorKey; |
| 254 | uint32_t uiAncestorMask = pSubsystemObjectCreator->getAncestorMask(); |
| 255 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 256 | for (uiAncestorKey = 0; uiAncestorKey < _contextMappingKeyArray.size(); uiAncestorKey++) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 257 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 258 | if (!((1 << uiAncestorKey) & uiAncestorMask)) { |
| 259 | // Ancestor not required |
| 260 | continue; |
| 261 | } |
| 262 | // Check ancestor was provided |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 263 | if (!context.iSet(uiAncestorKey)) { |
| 264 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 265 | getMappingError(strError, strKey, _contextMappingKeyArray[uiAncestorKey] + " not set", pInstanceConfigurableElement); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 266 | |
| 267 | return false; |
| 268 | } |
| 269 | } |
| 270 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 271 | // Then check configurable element size is correct |
| 272 | if (pInstanceConfigurableElement->getFootPrint() > pSubsystemObjectCreator->getMaxConfigurableElementSize()) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 273 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 274 | string strSizeError = "Size should not exceed " + pInstanceConfigurableElement->getFootprintAsString(); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 275 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 276 | getMappingError(strError, strKey, strSizeError, pInstanceConfigurableElement); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 277 | |
| 278 | return false; |
| 279 | } |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 280 | |
| 281 | // Do create object and keep its track |
| 282 | _subsystemObjectList.push_back(pSubsystemObjectCreator->objectCreate(*pStrValue, pInstanceConfigurableElement, context)); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 283 | |
| 284 | // Done |
| 285 | return true; |
| 286 | } |
| 287 | } |
| 288 | getMappingError(strError, "Mapping key", "Not found", pInstanceConfigurableElement); |
| 289 | |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | // Generic error handling from derived subsystem classes |
| 294 | void CSubsystem::getMappingError(string& strError, const string& strKey, const string& strMessage, const CInstanceConfigurableElement* pInstanceConfigurableElement) |
| 295 | { |
| 296 | strError = getName() + " " + getKind() + " mapping:\n" + strKey + " error : \"" + strMessage + "\" for element " + pInstanceConfigurableElement->getPath(); |
| 297 | } |
| 298 | |
| 299 | // From IMapper |
| 300 | bool CSubsystem::mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, string& strError) |
| 301 | { |
| 302 | // Get current context |
| 303 | CMappingContext context = _contextStack.top(); |
| 304 | |
| 305 | switch(pInstanceConfigurableElement->getType()) { |
| 306 | |
| 307 | case CInstanceConfigurableElement::EComponent: |
| 308 | |
| 309 | if (!handleMappingContext(pInstanceConfigurableElement, context, strError)) { |
| 310 | |
| 311 | return false; |
| 312 | } |
| 313 | break; |
| 314 | case CInstanceConfigurableElement::EParameterBlock: |
| 315 | case CInstanceConfigurableElement::EBitParameterBlock: |
| 316 | case CInstanceConfigurableElement::EParameter: |
| 317 | { |
| 318 | if (!handleSubsystemObjectCreation(pInstanceConfigurableElement, context, strError)) { |
| 319 | |
| 320 | return false; |
| 321 | } |
| 322 | break; |
| 323 | } |
| 324 | default: |
| 325 | assert(0); |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | // Push context |
| 330 | _contextStack.push(context); |
| 331 | |
| 332 | return true; |
| 333 | } |
| 334 | |
| 335 | void CSubsystem::mapEnd() |
| 336 | { |
| 337 | // Unstack context |
| 338 | _contextStack.pop(); |
| 339 | } |