blob: 996b54607f51bb01488798f78020efca84e5c72f [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +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;
37
38class CSubsystem : public CConfigurableElement, private IMapper
39{
40 // Subsystem objects iterator
41 typedef list<CSubsystemObject*>::const_iterator SubsystemObjectListIterator;
42public:
43 CSubsystem(const string& strName);
44 virtual ~CSubsystem();
45
46 // From IXmlSink
47 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
48
49 // Susbsystem Endianness
50 bool isBigEndian() const;
51
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010052 // Susbsystem sanity
53 virtual bool isAlive() const;
54
55 // Resynchronization after subsystem restart needed
56 virtual bool needResync(bool bClear);
57
Patrick Benavoli68a91282011-08-31 11:23:23 +020058 // XML configuration settings parsing
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020059 virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020060
61 // from CElement
62 virtual string getKind() const;
63protected:
64 // Parameter access
Patrick Benavoli065264a2011-11-20 15:46:41 +010065 virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020066 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ccab9d2011-11-10 23:21:01 +010067 // Used for simulation and virtual subsystems
Patrick Benavoli68a91282011-08-31 11:23:23 +020068 virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const;
69
70 /// Functionality intendedn for derived Subsystems
71 // Subsystem context mapping keys publication
72 void addContextMappingKey(const string& strMappingKey);
73 // Subsystem object creator publication (strong reference)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020074 void addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator);
Patrick Benavoli68a91282011-08-31 11:23:23 +020075private:
JhinX Lee4ebc0982012-07-12 17:50:07 +020076 CSubsystem(const CSubsystem&);
77 CSubsystem& operator=(const CSubsystem&);
78
Patrick Benavoli68a91282011-08-31 11:23:23 +020079 // Belonging subsystem
80 virtual const CSubsystem* getBelongingSubsystem() const;
81
82 // Mapping execution
83 bool mapSubsystemElements(string& strError);
84
Kevin Rocard3414f992013-04-02 19:49:40 +020085 /**
86 * Generic subsystem mapping error handling
87 *
88 * Format an human readable error string from a key and a message in case of mapping error
89 *
90 * @param[out] strError The formated error string
91 * @param[in] strKey The key on which the error refers
92 * @param[in] strMessage The error message
93 * @param[in] pInstanceConfigurableElement The element on wich the error refers
94 */
95 void getMappingError(string& strError, const string& strKey, const string& strMessage,
96 const CInstanceConfigurableElement* pInstanceConfigurableElement);
Patrick Benavoli68a91282011-08-31 11:23:23 +020097
Kevin Rocard084cafb2013-01-28 17:02:08 +010098 /**
99 * Handle a configurable element mapping.
100 *
101 * Add context mappings to the context and instantiate a subsystem object if needed.
102 *
103 * @param[in:out] pInstanceConfigurableElement The configurable element
104 * @param[out] bKeepDiving Keep diving for mapping keys
105 Is set to true if a subsystem object (tree leave) has been instantiated.
106 Undetermined on error
107 * @param[out] strError String filled with an human readable error on error,
108 left unmodified otherwise
109 *
110 * @return true on success, false on failure
111 */
Patrick Benavolid3a86bf2011-11-07 19:33:30 +0100112 virtual bool mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200113 virtual void mapEnd();
114
115 // Mapping generic context handling
116 bool handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError);
Kevin Rocard084cafb2013-01-28 17:02:08 +0100117
118 /**
119 * Looks if a subsystem object needs to be instantiated for the given configurable
120 * element, then instantiate it if needed.
121 *
122 * @param[in:out] pInstanceConfigurableElement The configurable element to check
123 * for instanciation
124 * @param[in] context The mapping values container
125 * @param[out] bHasCreatedSubsystemObject If a subsystem object has been instantiated.
126 Undetermined on error
127 * @param[out] strError String filled with an human readable error on error,
128 left unmodified otherwise
129 *
130 * @return true on success, false on failure
131 */
132 bool handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement,
133 CMappingContext& context, bool& bHasCreatedSubsystemObject, string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200134
135 // Subsystem context mapping keys
136 vector<string> _contextMappingKeyArray;
137
138 // Subsystem object creator map
139 vector<CSubsystemObjectCreator*> _subsystemObjectCreatorArray;
140
141 // Subsystem sync objects (house keeping)
142 list<CSubsystemObject*> _subsystemObjectList;
143
144 // Mapping Context stack
145 stack<CMappingContext> _contextStack;
146
147 // Subelements
148 CComponentLibrary* _pComponentLibrary;
149 CInstanceDefinition* _pInstanceDefinition;
150
151 // Endianness
152 bool _bBigEndian;
153};