| David Wagner | b76c9d6 | 2014-02-05 18:30:24 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011-2014, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without modification, |
| 6 | * are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | * list of conditions and the following disclaimer. |
| 10 | * |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer in the documentation and/or |
| 13 | * other materials provided with the distribution. |
| 14 | * |
| 15 | * 3. Neither the name of the copyright holder nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software without |
| 17 | * specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 29 | */ |
| 30 | #include "Subsystem.h" |
| 31 | #include "ComponentLibrary.h" |
| 32 | #include "InstanceDefinition.h" |
| 33 | #include "XmlParameterSerializingContext.h" |
| 34 | #include "ParameterAccessContext.h" |
| 35 | #include "ConfigurationAccessContext.h" |
| 36 | #include "SubsystemObjectCreator.h" |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 37 | #include "MappingData.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 38 | #include <assert.h> |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 39 | #include <sstream> |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 40 | |
| 41 | #define base CConfigurableElement |
| 42 | |
| 43 | CSubsystem::CSubsystem(const string& strName) : base(strName), _pComponentLibrary(new CComponentLibrary), _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false) |
| 44 | { |
| 45 | // Note: A subsystem contains instance components |
| 46 | // InstanceDefintion and ComponentLibrary objects are then not chosen to be children |
| 47 | // They'll be delt with locally |
| 48 | } |
| 49 | |
| 50 | CSubsystem::~CSubsystem() |
| 51 | { |
| 52 | // Remove subsystem objects |
| 53 | SubsystemObjectListIterator subsystemObjectIt; |
| 54 | |
| 55 | for (subsystemObjectIt = _subsystemObjectList.begin(); subsystemObjectIt != _subsystemObjectList.end(); ++subsystemObjectIt) { |
| 56 | |
| 57 | delete *subsystemObjectIt; |
| 58 | } |
| 59 | |
| 60 | // Remove susbsystem creators |
| 61 | uint32_t uiIndex; |
| 62 | |
| 63 | for (uiIndex = 0; uiIndex < _subsystemObjectCreatorArray.size(); uiIndex++) { |
| 64 | |
| 65 | delete _subsystemObjectCreatorArray[uiIndex]; |
| 66 | } |
| 67 | |
| 68 | // Order matters! |
| 69 | delete _pInstanceDefinition; |
| 70 | delete _pComponentLibrary; |
| 71 | } |
| 72 | |
| 73 | string CSubsystem::getKind() const |
| 74 | { |
| 75 | return "Subsystem"; |
| 76 | } |
| 77 | |
| 78 | // Susbsystem Endianness |
| 79 | bool CSubsystem::isBigEndian() const |
| 80 | { |
| 81 | return _bBigEndian; |
| 82 | } |
| 83 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 84 | // Susbsystem sanity |
| 85 | bool CSubsystem::isAlive() const |
| 86 | { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | // Resynchronization after subsystem restart needed |
| 91 | bool CSubsystem::needResync(bool bClear) |
| 92 | { |
| 93 | (void)bClear; |
| 94 | |
| 95 | return false; |
| 96 | } |
| 97 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 98 | // From IXmlSink |
| 99 | bool CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) |
| 100 | { |
| 101 | // Context |
| 102 | CXmlParameterSerializingContext& parameterBuildContext = static_cast<CXmlParameterSerializingContext&>(serializingContext); |
| 103 | |
| 104 | // Install temporary component library for further component creation |
| 105 | parameterBuildContext.setComponentLibrary(_pComponentLibrary); |
| 106 | |
| 107 | CXmlElement childElement; |
| 108 | |
| 109 | // XML populate ComponentLibrary |
| 110 | xmlElement.getChildElement("ComponentLibrary", childElement); |
| 111 | |
| 112 | if (!_pComponentLibrary->fromXml(childElement, serializingContext)) { |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | // XML populate InstanceDefintion |
| 118 | xmlElement.getChildElement("InstanceDefintion", childElement); |
| 119 | if (!_pInstanceDefinition->fromXml(childElement, serializingContext)) { |
| 120 | |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | // Create components |
| 125 | _pInstanceDefinition->createInstances(this); |
| 126 | |
| 127 | // Execute mapping to create subsystem mapping entities |
| 128 | string strError; |
| 129 | if (!mapSubsystemElements(strError)) { |
| 130 | |
| 131 | serializingContext.setError(strError); |
| 132 | |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | // Endianness |
| 137 | _bBigEndian = xmlElement.getAttributeBoolean("Endianness", "Big"); |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | // XML configuration settings parsing |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 143 | bool CSubsystem::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 144 | { |
| 145 | // Fix Endianness |
| 146 | configurationAccessContext.setBigEndianSubsystem(_bBigEndian); |
| 147 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 148 | return base::serializeXmlSettings(xmlConfigurationSettingsElementContent, configurationAccessContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | |
| 152 | bool CSubsystem::mapSubsystemElements(string& strError) |
| 153 | { |
| 154 | // Default mapping context |
| 155 | _contextStack.push(CMappingContext(_contextMappingKeyArray.size())); |
| 156 | |
| 157 | // Map all instantiated subelements in subsystem |
| 158 | uint32_t uiNbChildren = getNbChildren(); |
| 159 | uint32_t uiChild; |
| 160 | |
| 161 | for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { |
| 162 | |
| 163 | CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); |
| 164 | |
| 165 | if (!pInstanceConfigurableChildElement->map(*this, strError)) { |
| 166 | |
| 167 | return false; |
| 168 | } |
| 169 | } |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | // Parameter access |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 174 | bool CSubsystem::accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 175 | { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 176 | // Deal with Endianness |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 177 | parameterAccessContext.setBigEndianSubsystem(_bBigEndian); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 178 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 179 | return base::accessValue(pathNavigator, strValue, bSet, parameterAccessContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 182 | // Formats the mapping of the ConfigurableElements |
| 183 | string CSubsystem::formatMappingDataList( |
| 184 | const list<const CConfigurableElement*>& configurableElementPath) const |
| 185 | { |
| 186 | // The list is parsed in reverse order because it has been filled from the leaf to the trunk |
| 187 | // of the tree. When formatting the mapping, we want to start from the subsystem level |
| 188 | ostringstream ossStream; |
| 189 | list<const CConfigurableElement*>::const_reverse_iterator it; |
| 190 | for (it = configurableElementPath.rbegin(); it != configurableElementPath.rend(); ++it) { |
| 191 | |
| 192 | const CInstanceConfigurableElement* pInstanceConfigurableElement = |
| 193 | static_cast<const CInstanceConfigurableElement*>(*it); |
| 194 | |
| 195 | ossStream << pInstanceConfigurableElement->getFormattedMapping() << ", "; |
| 196 | } |
| 197 | return ossStream.str(); |
| 198 | } |
| 199 | |
| 200 | // Find the CSubystemObject containing a specific CInstanceConfigurableElement |
| 201 | const CSubsystemObject* CSubsystem::findSubsystemObjectFromConfigurableElement( |
| 202 | const CInstanceConfigurableElement* pInstanceConfigurableElement) const { |
| 203 | |
| 204 | const CSubsystemObject* pSubsystemObject = NULL; |
| 205 | |
| 206 | list<CSubsystemObject*>::const_iterator it; |
| 207 | for (it = _subsystemObjectList.begin(); it != _subsystemObjectList.end(); ++it) { |
| 208 | |
| 209 | // Check if one of the SubsystemObjects is associated with a ConfigurableElement |
| 210 | // corresponding to the expected one |
| 211 | pSubsystemObject = *it; |
| 212 | if (pSubsystemObject->getConfigurableElement() == pInstanceConfigurableElement) { |
| 213 | |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return pSubsystemObject; |
| 219 | } |
| 220 | |
| Frédéric Boisnard | 487ce85 | 2013-07-19 17:17:52 +0200 | [diff] [blame] | 221 | void CSubsystem::findSubsystemLevelMappingKeyValue( |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 222 | const CInstanceConfigurableElement* pInstanceConfigurableElement, |
| 223 | string& strMappingKey, |
| 224 | string& strMappingValue) const |
| 225 | { |
| 226 | // Find creator to get key name |
| 227 | vector<CSubsystemObjectCreator*>::const_iterator it; |
| 228 | for (it = _subsystemObjectCreatorArray.begin(); |
| 229 | it != _subsystemObjectCreatorArray.end(); ++it) { |
| 230 | |
| 231 | const CSubsystemObjectCreator* pSubsystemObjectCreator = *it; |
| 232 | |
| 233 | strMappingKey = pSubsystemObjectCreator->getMappingKey(); |
| 234 | |
| 235 | // Check if the ObjectCreator MappingKey corresponds to the element mapping data |
| 236 | const string* pStrValue; |
| 237 | if (pInstanceConfigurableElement->getMappingData(strMappingKey, pStrValue)) { |
| 238 | |
| 239 | strMappingValue = *pStrValue; |
| 240 | return; |
| 241 | } |
| 242 | } |
| 243 | assert(0); |
| 244 | } |
| 245 | |
| 246 | // Formats the mapping data as a comma separated list of key value pairs |
| 247 | string CSubsystem::getFormattedSubsystemMappingData( |
| 248 | const CInstanceConfigurableElement* pInstanceConfigurableElement) const |
| 249 | { |
| 250 | // Find the SubsystemObject related to pInstanceConfigurableElement |
| 251 | const CSubsystemObject* pSubsystemObject = findSubsystemObjectFromConfigurableElement( |
| 252 | pInstanceConfigurableElement); |
| 253 | |
| 254 | // Exit if node does not correspond to a SubsystemObject |
| 255 | if (pSubsystemObject == NULL) { |
| 256 | |
| 257 | return ""; |
| 258 | } |
| 259 | |
| 260 | // Find SubsystemCreator mapping key |
| 261 | string strMappingKey; |
| 262 | string strMappingValue; // mapping value where amends are not replaced by their value |
| Frédéric Boisnard | 487ce85 | 2013-07-19 17:17:52 +0200 | [diff] [blame] | 263 | findSubsystemLevelMappingKeyValue(pInstanceConfigurableElement, strMappingKey, strMappingValue); |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 264 | |
| 265 | // Find SubSystemObject mapping value (with amends replaced by their value) |
| 266 | return strMappingKey + ":" + pSubsystemObject->getFormattedMappingValue(); |
| 267 | } |
| 268 | |
| 269 | string CSubsystem::getMapping(list<const CConfigurableElement*>& configurableElementPath) const |
| 270 | { |
| 271 | if (configurableElementPath.empty()) { |
| 272 | |
| 273 | return ""; |
| 274 | } |
| 275 | |
| 276 | // Get the first element, which is the element containing the amended mapping |
| 277 | const CInstanceConfigurableElement* pInstanceConfigurableElement = |
| 278 | static_cast<const CInstanceConfigurableElement*>(configurableElementPath.front()); |
| 279 | configurableElementPath.pop_front(); |
| 280 | // Now the list only contains elements whose mapping are related to the context |
| 281 | |
| 282 | // Format context mapping data |
| 283 | string strValue = formatMappingDataList(configurableElementPath); |
| 284 | |
| 285 | // Print the mapping of the first node, which corresponds to a SubsystemObject |
| 286 | strValue += getFormattedSubsystemMappingData(pInstanceConfigurableElement); |
| 287 | |
| 288 | return strValue; |
| 289 | } |
| 290 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 291 | void CSubsystem::logValue(string& strValue, CErrorContext& errorContext) const |
| 292 | { |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 293 | CParameterAccessContext& parameterAccessContext = static_cast<CParameterAccessContext&>(errorContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 294 | |
| 295 | // Deal with Endianness |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 296 | parameterAccessContext.setBigEndianSubsystem(_bBigEndian); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 297 | |
| 298 | return base::logValue(strValue, errorContext); |
| 299 | } |
| 300 | |
| Patrick Benavoli | 6ccab9d | 2011-11-10 23:21:01 +0100 | [diff] [blame] | 301 | // Used for simulation and virtual subsystems |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 302 | void CSubsystem::setDefaultValues(CParameterAccessContext& parameterAccessContext) const |
| 303 | { |
| 304 | // Deal with Endianness |
| 305 | parameterAccessContext.setBigEndianSubsystem(_bBigEndian); |
| 306 | |
| 307 | base::setDefaultValues(parameterAccessContext); |
| 308 | } |
| 309 | |
| 310 | // Belonging subsystem |
| 311 | const CSubsystem* CSubsystem::getBelongingSubsystem() const |
| 312 | { |
| 313 | return this; |
| 314 | } |
| 315 | |
| 316 | // Subsystem context mapping keys publication |
| 317 | void CSubsystem::addContextMappingKey(const string& strMappingKey) |
| 318 | { |
| 319 | _contextMappingKeyArray.push_back(strMappingKey); |
| 320 | } |
| 321 | |
| 322 | // Subsystem object creator publication (strong reference) |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 323 | void CSubsystem::addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 324 | { |
| 325 | _subsystemObjectCreatorArray.push_back(pSubsystemObjectCreator); |
| 326 | } |
| 327 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 328 | // Generic error handling from derived subsystem classes |
| 329 | string CSubsystem::getMappingError(const string& strKey, |
| 330 | const string& strMessage, |
| 331 | const CInstanceConfigurableElement* pInstanceConfigurableElement) |
| 332 | const |
| 333 | { |
| 334 | return getName() + " " + getKind() + " " + |
| 335 | "mapping:\n" + strKey + " " + |
| 336 | "error: \"" + strMessage + "\" " + |
| 337 | "for element " + pInstanceConfigurableElement->getPath(); |
| 338 | } |
| 339 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 340 | // Mapping generic context handling |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 341 | bool CSubsystem::handleMappingContext( |
| 342 | const CInstanceConfigurableElement* pInstanceConfigurableElement, |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 343 | CMappingContext& context, |
| 344 | string& strError) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 345 | { |
| 346 | // Feed context with found mapping data |
| 347 | uint32_t uiItem; |
| 348 | |
| Renaud de Chivre | 46966e0 | 2013-09-02 10:48:36 +0200 | [diff] [blame] | 349 | for (uiItem = 0; uiItem < _contextMappingKeyArray.size(); uiItem++) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 350 | |
| Renaud de Chivre | 46966e0 | 2013-09-02 10:48:36 +0200 | [diff] [blame] | 351 | const string& strKey = _contextMappingKeyArray[uiItem]; |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 352 | const string* pStrValue; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 353 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 354 | if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 355 | // Assign item to context |
| Renaud de Chivre | 46966e0 | 2013-09-02 10:48:36 +0200 | [diff] [blame] | 356 | if (!context.setItem(uiItem, &strKey, pStrValue)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 357 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 358 | strError = getMappingError(strKey, "Already set", pInstanceConfigurableElement); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 359 | |
| 360 | return false; |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | return true; |
| 365 | } |
| 366 | |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 367 | // Subsystem object creation handling |
| 368 | bool CSubsystem::handleSubsystemObjectCreation( |
| 369 | CInstanceConfigurableElement* pInstanceConfigurableElement, |
| 370 | CMappingContext& context, bool& bHasCreatedSubsystemObject, string& strError) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 371 | { |
| 372 | uint32_t uiItem; |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 373 | bHasCreatedSubsystemObject = false; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 374 | |
| 375 | for (uiItem = 0; uiItem < _subsystemObjectCreatorArray.size(); uiItem++) { |
| 376 | |
| Kevin Rocard | 3414f99 | 2013-04-02 19:49:40 +0200 | [diff] [blame] | 377 | const CSubsystemObjectCreator* pSubsystemObjectCreator = |
| 378 | _subsystemObjectCreatorArray[uiItem]; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 379 | |
| 380 | // Mapping key |
| 381 | string strKey = pSubsystemObjectCreator->getMappingKey(); |
| 382 | // Object id |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 383 | const string* pStrValue; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 384 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 385 | if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 386 | |
| Kevin Rocard | 3414f99 | 2013-04-02 19:49:40 +0200 | [diff] [blame] | 387 | // First check context consistency |
| 388 | // (required ancestors must have been set prior to object creation) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 389 | uint32_t uiAncestorKey; |
| 390 | uint32_t uiAncestorMask = pSubsystemObjectCreator->getAncestorMask(); |
| 391 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 392 | for (uiAncestorKey = 0; uiAncestorKey < _contextMappingKeyArray.size(); uiAncestorKey++) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 393 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 394 | if (!((1 << uiAncestorKey) & uiAncestorMask)) { |
| 395 | // Ancestor not required |
| 396 | continue; |
| 397 | } |
| 398 | // Check ancestor was provided |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 399 | if (!context.iSet(uiAncestorKey)) { |
| 400 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 401 | strError = getMappingError(strKey, _contextMappingKeyArray[uiAncestorKey] + |
| 402 | " not set", pInstanceConfigurableElement); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 403 | |
| 404 | return false; |
| 405 | } |
| 406 | } |
| 407 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 408 | // Then check configurable element size is correct |
| Kevin Rocard | 3414f99 | 2013-04-02 19:49:40 +0200 | [diff] [blame] | 409 | if (pInstanceConfigurableElement->getFootPrint() > |
| 410 | pSubsystemObjectCreator->getMaxConfigurableElementSize()) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 411 | |
| Kevin Rocard | 3414f99 | 2013-04-02 19:49:40 +0200 | [diff] [blame] | 412 | string strSizeError = "Size should not exceed " + |
| 413 | pSubsystemObjectCreator->getMaxConfigurableElementSize(); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 414 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 415 | strError = getMappingError(strKey, strSizeError, pInstanceConfigurableElement); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 416 | |
| 417 | return false; |
| 418 | } |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 419 | |
| 420 | // Do create object and keep its track |
| Kevin Rocard | 3414f99 | 2013-04-02 19:49:40 +0200 | [diff] [blame] | 421 | _subsystemObjectList.push_back(pSubsystemObjectCreator->objectCreate( |
| 422 | *pStrValue, pInstanceConfigurableElement, context)); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 423 | |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 424 | // Indicate subsytem creation to caller |
| 425 | bHasCreatedSubsystemObject = true; |
| 426 | |
| 427 | // The subsystem Object has been instantiated, no need to continue looking for an |
| 428 | // instantiation mapping |
| 429 | break; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 430 | } |
| 431 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 432 | |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 433 | return true; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 436 | // From IMapper |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 437 | // Handle a configurable element mapping |
| 438 | bool CSubsystem::mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, |
| 439 | bool& bKeepDiving, string& strError) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 440 | { |
| 441 | // Get current context |
| 442 | CMappingContext context = _contextStack.top(); |
| 443 | |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 444 | // Add mapping in context |
| Renaud de Chivre | 46966e0 | 2013-09-02 10:48:36 +0200 | [diff] [blame] | 445 | if (!handleMappingContext(pInstanceConfigurableElement, context, |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 446 | strError)) { |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 447 | |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | // Push context |
| 452 | _contextStack.push(context); |
| 453 | |
| 454 | // Assume diving by default |
| 455 | bKeepDiving = true; |
| 456 | |
| 457 | // Deal with ambiguous usage of parameter blocks |
| 458 | bool bShouldCreateSubsystemObject = true; |
| 459 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 460 | switch(pInstanceConfigurableElement->getType()) { |
| 461 | |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 462 | case CInstanceConfigurableElement::EComponent: |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 463 | case CInstanceConfigurableElement::EParameterBlock: |
| 464 | // Subsystem object creation is optional in parameter blocks |
| 465 | bShouldCreateSubsystemObject = false; |
| 466 | // No break |
| 467 | case CInstanceConfigurableElement::EBitParameterBlock: |
| 468 | case CInstanceConfigurableElement::EParameter: |
| 469 | case CInstanceConfigurableElement::EStringParameter: |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 470 | |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 471 | bool bHasCreatedSubsystemObject; |
| 472 | |
| 473 | if (!handleSubsystemObjectCreation(pInstanceConfigurableElement, context, |
| 474 | bHasCreatedSubsystemObject, strError)) { |
| 475 | |
| 476 | return false; |
| 477 | } |
| 478 | // Check for creation error |
| 479 | if (bShouldCreateSubsystemObject && !bHasCreatedSubsystemObject) { |
| 480 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 481 | strError = getMappingError("Not found", |
| 482 | "Subsystem object mapping key is missing", |
| 483 | pInstanceConfigurableElement); |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 484 | return false; |
| 485 | } |
| 486 | // Not created and no error, keep diving |
| 487 | bKeepDiving = !bHasCreatedSubsystemObject; |
| 488 | |
| 489 | return true; |
| 490 | |
| 491 | default: |
| 492 | assert(0); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 493 | return false; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 494 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | void CSubsystem::mapEnd() |
| 498 | { |
| 499 | // Unstack context |
| 500 | _contextStack.pop(); |
| 501 | } |