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