blob: 63546ada16bd661a2df06e9095c7e93e788a88d3 [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * 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 Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#pragma once
26
27#include "ConfigurableElement.h"
28#include "Mapper.h"
29#include "MappingContext.h"
30#include <stack>
31#include <vector>
32
33class CInstanceDefinition;
34class CComponentLibrary;
35class CSubsystemObject;
36class CSubsystemObjectCreator;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020037class CInstanceConfigurableElement;
Patrick Benavoli68a91282011-08-31 11:23:23 +020038
39class CSubsystem : public CConfigurableElement, private IMapper
40{
41 // Subsystem objects iterator
42 typedef list<CSubsystemObject*>::const_iterator SubsystemObjectListIterator;
43public:
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 Denneulinf2fd15a2012-12-20 17:53:29 +010053 // Susbsystem sanity
54 virtual bool isAlive() const;
55
56 // Resynchronization after subsystem restart needed
57 virtual bool needResync(bool bClear);
58
Patrick Benavoli68a91282011-08-31 11:23:23 +020059 // XML configuration settings parsing
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020060 virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020061
62 // from CElement
63 virtual string getKind() const;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020064
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 Benavoli68a91282011-08-31 11:23:23 +020081protected:
82 // Parameter access
Patrick Benavoli065264a2011-11-20 15:46:41 +010083 virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020084 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ccab9d2011-11-10 23:21:01 +010085 // Used for simulation and virtual subsystems
Patrick Benavoli68a91282011-08-31 11:23:23 +020086 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 Benavoli6ba361d2011-08-31 11:23:24 +020092 void addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator);
Patrick Benavoli68a91282011-08-31 11:23:23 +020093private:
JhinX Lee4ebc0982012-07-12 17:50:07 +020094 CSubsystem(const CSubsystem&);
95 CSubsystem& operator=(const CSubsystem&);
96
Patrick Benavoli68a91282011-08-31 11:23:23 +020097 // Belonging subsystem
98 virtual const CSubsystem* getBelongingSubsystem() const;
99
100 // Mapping execution
101 bool mapSubsystemElements(string& strError);
102
Kevin Rocard3414f992013-04-02 19:49:40 +0200103 /**
Kevin Rocard084cafb2013-01-28 17:02:08 +0100104 * 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 Benavolid3a86bf2011-11-07 19:33:30 +0100117 virtual bool mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200118 virtual void mapEnd();
119
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200120 // 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 Boisnard487ce852013-07-19 17:17:52 +0200163 * corresponds to Subsystem level mapping (Subsystem level mapping keys are defined in
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200164 * 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 Boisnard487ce852013-07-19 17:17:52 +0200172 void findSubsystemLevelMappingKeyValue(
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200173 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 Boisnard6cae0ec2013-05-23 18:48:58 +0200192 * @param[out] context The context mapping to update with the current element mapping values
193 * @param[out] strError The formated error string
Renaud de Chivre46966e02013-09-02 10:48:36 +0200194 *
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200195 * @return true on success
196 */
197 bool handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement,
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200198 CMappingContext& context,
199 string& strError) const;
Kevin Rocard084cafb2013-01-28 17:02:08 +0100200
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 Boisnard6cae0ec2013-05-23 18:48:58 +0200216 CMappingContext& context, bool& bHasCreatedSubsystemObject,
217 string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200218
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};