| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 1 | /* |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 2 | * INTEL CONFIDENTIAL |
| 3 | * Copyright © 2011 Intel |
| 4 | * Corporation All Rights Reserved. |
| 5 | * |
| 6 | * The source code contained or described herein and all documents related to |
| 7 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 8 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 9 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 10 | * and confidential information of Intel or its suppliers and licensors. The |
| 11 | * Material is protected by worldwide copyright and trade secret laws and |
| 12 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 13 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 14 | * disclosed in any way without Intel’s prior express written permission. |
| 15 | * |
| 16 | * No license under any patent, copyright, trade secret or other intellectual |
| 17 | * property right is granted to or conferred upon you by disclosure or delivery |
| 18 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 19 | * otherwise. Any license under such intellectual property rights must be |
| 20 | * express and approved by Intel in writing. |
| 21 | * |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 22 | * CREATED: 2011-06-01 |
| 23 | * UPDATED: 2011-07-27 |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 24 | */ |
| 25 | #pragma once |
| 26 | |
| 27 | #include "ConfigurableElement.h" |
| 28 | #include "Mapper.h" |
| 29 | #include "MappingContext.h" |
| 30 | #include <stack> |
| 31 | #include <vector> |
| 32 | |
| 33 | class CInstanceDefinition; |
| 34 | class CComponentLibrary; |
| 35 | class CSubsystemObject; |
| 36 | class CSubsystemObjectCreator; |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 37 | class CInstanceConfigurableElement; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 38 | |
| 39 | class CSubsystem : public CConfigurableElement, private IMapper |
| 40 | { |
| 41 | // Subsystem objects iterator |
| 42 | typedef list<CSubsystemObject*>::const_iterator SubsystemObjectListIterator; |
| 43 | public: |
| 44 | CSubsystem(const string& strName); |
| 45 | virtual ~CSubsystem(); |
| 46 | |
| 47 | // From IXmlSink |
| 48 | virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); |
| 49 | |
| 50 | // Susbsystem Endianness |
| 51 | bool isBigEndian() const; |
| 52 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 53 | // Susbsystem sanity |
| 54 | virtual bool isAlive() const; |
| 55 | |
| 56 | // Resynchronization after subsystem restart needed |
| 57 | virtual bool needResync(bool bClear); |
| 58 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 59 | // XML configuration settings parsing |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 60 | virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 61 | |
| 62 | // from CElement |
| 63 | virtual string getKind() const; |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Fetch mapping data of an element. |
| 67 | * |
| 68 | * The mapping is represented as a string of all the mapping data (key:value) defined in the |
| 69 | * context of the element. |
| 70 | * This method gathers the mapping data found in each Element of the configurableElementPath |
| 71 | * list to format the resulting string. |
| 72 | * |
| 73 | * @param[in] configurableElementPath List of all the ConfigurableElements found |
| 74 | * that have a mapping. Elements are added at the end of the list, so the root Element will be |
| 75 | * the last one. |
| 76 | * |
| 77 | * @return Formatted string of the mapping data |
| 78 | */ |
| 79 | virtual string getMapping(list<const CConfigurableElement*>& configurableElementPath) const; |
| 80 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 81 | protected: |
| 82 | // Parameter access |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 83 | virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 84 | virtual void logValue(string& strValue, CErrorContext& errorContext) const; |
| Patrick Benavoli | 6ccab9d | 2011-11-10 23:21:01 +0100 | [diff] [blame] | 85 | // Used for simulation and virtual subsystems |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 86 | virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const; |
| 87 | |
| 88 | /// Functionality intendedn for derived Subsystems |
| 89 | // Subsystem context mapping keys publication |
| 90 | void addContextMappingKey(const string& strMappingKey); |
| 91 | // Subsystem object creator publication (strong reference) |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 92 | void addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 93 | private: |
| JhinX Lee | 4ebc098 | 2012-07-12 17:50:07 +0200 | [diff] [blame] | 94 | CSubsystem(const CSubsystem&); |
| 95 | CSubsystem& operator=(const CSubsystem&); |
| 96 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 97 | // Belonging subsystem |
| 98 | virtual const CSubsystem* getBelongingSubsystem() const; |
| 99 | |
| 100 | // Mapping execution |
| 101 | bool mapSubsystemElements(string& strError); |
| 102 | |
| Kevin Rocard | 3414f99 | 2013-04-02 19:49:40 +0200 | [diff] [blame] | 103 | /** |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 104 | * Handle a configurable element mapping. |
| 105 | * |
| 106 | * Add context mappings to the context and instantiate a subsystem object if needed. |
| 107 | * |
| 108 | * @param[in:out] pInstanceConfigurableElement The configurable element |
| 109 | * @param[out] bKeepDiving Keep diving for mapping keys |
| 110 | Is set to true if a subsystem object (tree leave) has been instantiated. |
| 111 | Undetermined on error |
| 112 | * @param[out] strError String filled with an human readable error on error, |
| 113 | left unmodified otherwise |
| 114 | * |
| 115 | * @return true on success, false on failure |
| 116 | */ |
| Patrick Benavoli | d3a86bf | 2011-11-07 19:33:30 +0100 | [diff] [blame] | 117 | virtual bool mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 118 | virtual void mapEnd(); |
| 119 | |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 120 | // Mapping access |
| 121 | /** |
| 122 | * Generic mapping error handling |
| 123 | * |
| 124 | * Format an human readable error string from a key and a message in case of mapping error |
| 125 | * |
| 126 | * @param[in] strKey The key on which the error refers |
| 127 | * @param[in] strMessage The error message |
| 128 | * @param[in] pInstanceConfigurableElement The element on wich the error refers |
| 129 | * |
| 130 | * returns The formated error string |
| 131 | */ |
| 132 | string getMappingError(const string& strKey, |
| 133 | const string& strMessage, |
| 134 | const CInstanceConfigurableElement* pInstanceConfigurableElement) const; |
| 135 | |
| 136 | /** |
| 137 | * Format the mapping data of the ConfigurableElements that have been gathered through recursive |
| 138 | * calls to the getMapping() method. |
| 139 | * These elements shall be evaluated from the root level to the leaves level, so the list must |
| 140 | * be parsed in reverse order. |
| 141 | * |
| 142 | * @param[in] configurableElementPath List of ConfigurableElements containing mapping data |
| 143 | * |
| 144 | * @return String containing the formatted mapping |
| 145 | */ |
| 146 | string formatMappingDataList( |
| 147 | const list<const CConfigurableElement*>& configurableElementPath) const; |
| 148 | |
| 149 | /** |
| 150 | * Find the SubystemObject which contains a specific CInstanceConfigurableElement. |
| 151 | * |
| 152 | * @param[in] pInstanceConfigurableElement The CInstanceConfigurableElement that is related to |
| 153 | * the wanted SubsystemObject. Each SubsystemObject of the Subystem internal list is checked in |
| 154 | * order to find a match. |
| 155 | * |
| 156 | * @return A pointer to the SubsystemObject related to pInstanceConfigurableElement |
| 157 | */ |
| 158 | const CSubsystemObject* findSubsystemObjectFromConfigurableElement( |
| 159 | const CInstanceConfigurableElement* pInstanceConfigurableElement) const; |
| 160 | |
| 161 | /** |
| 162 | * Find the mapping data defined for the CInstanceConfigurableElement given in parameter, that |
| Frédéric Boisnard | 487ce85 | 2013-07-19 17:17:52 +0200 | [diff] [blame] | 163 | * corresponds to Subsystem level mapping (Subsystem level mapping keys are defined in |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 164 | * CSubsystemObjectCreator classes). |
| 165 | * The CInstanceConfigurableElement might as well contain local mapping data. |
| 166 | * |
| 167 | * @param[in] pInstanceConfigurableElement The element which mapping data will be parsed for |
| 168 | * a match |
| 169 | * @param[out] strMappingKey Mapping key defined at the Subsystem level |
| 170 | * @param[out] strMappingValue Mapping value contained in pInstanceConfigurableElement |
| 171 | */ |
| Frédéric Boisnard | 487ce85 | 2013-07-19 17:17:52 +0200 | [diff] [blame] | 172 | void findSubsystemLevelMappingKeyValue( |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 173 | const CInstanceConfigurableElement* pInstanceConfigurableElement, |
| 174 | string& strMappingKey, |
| 175 | string& strMappingValue) const; |
| 176 | |
| 177 | /** |
| 178 | * Formats the mapping of a SubsystemObject |
| 179 | * |
| 180 | * @param[in] pInstanceConfigurableElement Element corresponding to a SubsystemObject |
| 181 | * |
| 182 | * @return String containing the formatted mapping |
| 183 | */ |
| 184 | string getFormattedSubsystemMappingData( |
| 185 | const CInstanceConfigurableElement* pInstanceConfigurableElement) const; |
| 186 | /** |
| 187 | * Generic context handling |
| 188 | * |
| 189 | * Feed context with mapping data of the current element |
| 190 | * |
| 191 | * @param[in] pInstanceConfigurableElement The element containing mapping data |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 192 | * @param[out] context The context mapping to update with the current element mapping values |
| 193 | * @param[out] strError The formated error string |
| Renaud de Chivre | 46966e0 | 2013-09-02 10:48:36 +0200 | [diff] [blame^] | 194 | * |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 195 | * @return true on success |
| 196 | */ |
| 197 | bool handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 198 | CMappingContext& context, |
| 199 | string& strError) const; |
| Kevin Rocard | 084cafb | 2013-01-28 17:02:08 +0100 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * Looks if a subsystem object needs to be instantiated for the given configurable |
| 203 | * element, then instantiate it if needed. |
| 204 | * |
| 205 | * @param[in:out] pInstanceConfigurableElement The configurable element to check |
| 206 | * for instanciation |
| 207 | * @param[in] context The mapping values container |
| 208 | * @param[out] bHasCreatedSubsystemObject If a subsystem object has been instantiated. |
| 209 | Undetermined on error |
| 210 | * @param[out] strError String filled with an human readable error on error, |
| 211 | left unmodified otherwise |
| 212 | * |
| 213 | * @return true on success, false on failure |
| 214 | */ |
| 215 | bool handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement, |
| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame] | 216 | CMappingContext& context, bool& bHasCreatedSubsystemObject, |
| 217 | string& strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 218 | |
| 219 | // Subsystem context mapping keys |
| 220 | vector<string> _contextMappingKeyArray; |
| 221 | |
| 222 | // Subsystem object creator map |
| 223 | vector<CSubsystemObjectCreator*> _subsystemObjectCreatorArray; |
| 224 | |
| 225 | // Subsystem sync objects (house keeping) |
| 226 | list<CSubsystemObject*> _subsystemObjectList; |
| 227 | |
| 228 | // Mapping Context stack |
| 229 | stack<CMappingContext> _contextStack; |
| 230 | |
| 231 | // Subelements |
| 232 | CComponentLibrary* _pComponentLibrary; |
| 233 | CInstanceDefinition* _pInstanceDefinition; |
| 234 | |
| 235 | // Endianness |
| 236 | bool _bBigEndian; |
| 237 | }; |