blob: a03a2ef4421f3adf4277b9086f474018dd515d1a [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001/*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * 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 Benavoli68a91282011-08-31 11:23:23 +020029 */
30#pragma once
31
32#include "ConfigurableElement.h"
David Wagner01c74952014-03-05 10:55:15 +010033#include "ConfigurableElementWithMapping.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020034#include "Mapper.h"
35#include "MappingContext.h"
36#include <stack>
37#include <vector>
38
39class CInstanceDefinition;
40class CComponentLibrary;
41class CSubsystemObject;
42class CSubsystemObjectCreator;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020043class CInstanceConfigurableElement;
David Wagner01c74952014-03-05 10:55:15 +010044class CMappingData;
Patrick Benavoli68a91282011-08-31 11:23:23 +020045
David Wagner01c74952014-03-05 10:55:15 +010046class CSubsystem : public CConfigurableElementWithMapping, private IMapper
Patrick Benavoli68a91282011-08-31 11:23:23 +020047{
48 // Subsystem objects iterator
49 typedef list<CSubsystemObject*>::const_iterator SubsystemObjectListIterator;
50public:
51 CSubsystem(const string& strName);
52 virtual ~CSubsystem();
53
54 // From IXmlSink
55 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
56
57 // Susbsystem Endianness
58 bool isBigEndian() const;
59
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010060 // Susbsystem sanity
61 virtual bool isAlive() const;
62
63 // Resynchronization after subsystem restart needed
64 virtual bool needResync(bool bClear);
65
Patrick Benavoli68a91282011-08-31 11:23:23 +020066 // XML configuration settings parsing
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020067 virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020068
69 // from CElement
70 virtual string getKind() const;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020071
David Wagner01c74952014-03-05 10:55:15 +010072 virtual bool getMappingData(const std::string& strKey, const std::string*& pStrValue) const;
73
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020074 /**
75 * Fetch mapping data of an element.
76 *
77 * The mapping is represented as a string of all the mapping data (key:value) defined in the
78 * context of the element.
79 * This method gathers the mapping data found in each Element of the configurableElementPath
80 * list to format the resulting string.
81 *
82 * @param[in] configurableElementPath List of all the ConfigurableElements found
83 * that have a mapping. Elements are added at the end of the list, so the root Element will be
84 * the last one.
85 *
86 * @return Formatted string of the mapping data
87 */
88 virtual string getMapping(list<const CConfigurableElement*>& configurableElementPath) const;
89
Patrick Benavoli68a91282011-08-31 11:23:23 +020090protected:
91 // Parameter access
Patrick Benavoli065264a2011-11-20 15:46:41 +010092 virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020093 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ccab9d2011-11-10 23:21:01 +010094 // Used for simulation and virtual subsystems
Patrick Benavoli68a91282011-08-31 11:23:23 +020095 virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const;
96
97 /// Functionality intendedn for derived Subsystems
98 // Subsystem context mapping keys publication
99 void addContextMappingKey(const string& strMappingKey);
100 // Subsystem object creator publication (strong reference)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200101 void addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200102private:
JhinX Lee4ebc0982012-07-12 17:50:07 +0200103 CSubsystem(const CSubsystem&);
104 CSubsystem& operator=(const CSubsystem&);
105
Patrick Benavoli68a91282011-08-31 11:23:23 +0200106 // Belonging subsystem
107 virtual const CSubsystem* getBelongingSubsystem() const;
108
109 // Mapping execution
110 bool mapSubsystemElements(string& strError);
111
Kevin Rocard3414f992013-04-02 19:49:40 +0200112 /**
Kevin Rocard084cafb2013-01-28 17:02:08 +0100113 * Handle a configurable element mapping.
114 *
115 * Add context mappings to the context and instantiate a subsystem object if needed.
116 *
117 * @param[in:out] pInstanceConfigurableElement The configurable element
118 * @param[out] bKeepDiving Keep diving for mapping keys
119 Is set to true if a subsystem object (tree leave) has been instantiated.
120 Undetermined on error
121 * @param[out] strError String filled with an human readable error on error,
122 left unmodified otherwise
123 *
124 * @return true on success, false on failure
125 */
Patrick Benavolid3a86bf2011-11-07 19:33:30 +0100126 virtual bool mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200127 virtual void mapEnd();
128
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200129 // Mapping access
130 /**
131 * Generic mapping error handling
132 *
133 * Format an human readable error string from a key and a message in case of mapping error
134 *
135 * @param[in] strKey The key on which the error refers
136 * @param[in] strMessage The error message
David Wagner01c74952014-03-05 10:55:15 +0100137 * @param[in] pConfigurableElementWithMapping The element on which the error refers
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200138 *
139 * returns The formated error string
140 */
David Wagner01c74952014-03-05 10:55:15 +0100141 string getMappingError(
142 const string& strKey,
143 const string& strMessage,
144 const CConfigurableElementWithMapping* pConfigurableElementWithMapping) const;
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200145
146 /**
147 * Format the mapping data of the ConfigurableElements that have been gathered through recursive
148 * calls to the getMapping() method.
149 * These elements shall be evaluated from the root level to the leaves level, so the list must
150 * be parsed in reverse order.
151 *
152 * @param[in] configurableElementPath List of ConfigurableElements containing mapping data
153 *
154 * @return String containing the formatted mapping
155 */
156 string formatMappingDataList(
157 const list<const CConfigurableElement*>& configurableElementPath) const;
158
159 /**
160 * Find the SubystemObject which contains a specific CInstanceConfigurableElement.
161 *
162 * @param[in] pInstanceConfigurableElement The CInstanceConfigurableElement that is related to
163 * the wanted SubsystemObject. Each SubsystemObject of the Subystem internal list is checked in
164 * order to find a match.
165 *
166 * @return A pointer to the SubsystemObject related to pInstanceConfigurableElement
167 */
168 const CSubsystemObject* findSubsystemObjectFromConfigurableElement(
169 const CInstanceConfigurableElement* pInstanceConfigurableElement) const;
170
171 /**
172 * Find the mapping data defined for the CInstanceConfigurableElement given in parameter, that
Frédéric Boisnard487ce852013-07-19 17:17:52 +0200173 * corresponds to Subsystem level mapping (Subsystem level mapping keys are defined in
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200174 * CSubsystemObjectCreator classes).
175 * The CInstanceConfigurableElement might as well contain local mapping data.
176 *
177 * @param[in] pInstanceConfigurableElement The element which mapping data will be parsed for
178 * a match
179 * @param[out] strMappingKey Mapping key defined at the Subsystem level
180 * @param[out] strMappingValue Mapping value contained in pInstanceConfigurableElement
181 */
Frédéric Boisnard487ce852013-07-19 17:17:52 +0200182 void findSubsystemLevelMappingKeyValue(
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200183 const CInstanceConfigurableElement* pInstanceConfigurableElement,
184 string& strMappingKey,
185 string& strMappingValue) const;
186
187 /**
188 * Formats the mapping of a SubsystemObject
189 *
190 * @param[in] pInstanceConfigurableElement Element corresponding to a SubsystemObject
191 *
192 * @return String containing the formatted mapping
193 */
194 string getFormattedSubsystemMappingData(
195 const CInstanceConfigurableElement* pInstanceConfigurableElement) const;
196 /**
197 * Generic context handling
198 *
199 * Feed context with mapping data of the current element
200 *
David Wagner01c74952014-03-05 10:55:15 +0100201 * @param[in] pConfigurableElementWithMapping The element containing mapping data
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200202 * @param[out] context The context mapping to update with the current element mapping values
203 * @param[out] strError The formated error string
Renaud de Chivre46966e02013-09-02 10:48:36 +0200204 *
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200205 * @return true on success
206 */
David Wagner01c74952014-03-05 10:55:15 +0100207 bool handleMappingContext(
208 const CConfigurableElementWithMapping* pConfigurableElementWithMapping,
209 CMappingContext& context,
210 string& strError) const;
Kevin Rocard084cafb2013-01-28 17:02:08 +0100211
212 /**
213 * Looks if a subsystem object needs to be instantiated for the given configurable
214 * element, then instantiate it if needed.
215 *
216 * @param[in:out] pInstanceConfigurableElement The configurable element to check
217 * for instanciation
218 * @param[in] context The mapping values container
219 * @param[out] bHasCreatedSubsystemObject If a subsystem object has been instantiated.
220 Undetermined on error
221 * @param[out] strError String filled with an human readable error on error,
222 left unmodified otherwise
223 *
224 * @return true on success, false on failure
225 */
226 bool handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement,
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200227 CMappingContext& context, bool& bHasCreatedSubsystemObject,
228 string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200229
230 // Subsystem context mapping keys
231 vector<string> _contextMappingKeyArray;
232
233 // Subsystem object creator map
234 vector<CSubsystemObjectCreator*> _subsystemObjectCreatorArray;
235
236 // Subsystem sync objects (house keeping)
237 list<CSubsystemObject*> _subsystemObjectList;
238
239 // Mapping Context stack
240 stack<CMappingContext> _contextStack;
241
242 // Subelements
243 CComponentLibrary* _pComponentLibrary;
244 CInstanceDefinition* _pInstanceDefinition;
245
246 // Endianness
247 bool _bBigEndian;
David Wagner01c74952014-03-05 10:55:15 +0100248
249 //! Contains the mapping info at Subsystem level
250 CMappingData* _pMappingData;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200251};