Subsystem.h revision 3414f994f9d2bf971caa4abd03932529619a81ec
193250d172612c405135d56ffd306deae5ebc6df1Kevin Rocard/*
268a912857707864bbaaff9808717813105072a6ePatrick Benavoli * INTEL CONFIDENTIAL
368a912857707864bbaaff9808717813105072a6ePatrick Benavoli * Copyright © 2011 Intel
468a912857707864bbaaff9808717813105072a6ePatrick Benavoli * Corporation All Rights Reserved.
568a912857707864bbaaff9808717813105072a6ePatrick Benavoli *
668a912857707864bbaaff9808717813105072a6ePatrick Benavoli * The source code contained or described herein and all documents related to
768a912857707864bbaaff9808717813105072a6ePatrick Benavoli * the source code ("Material") are owned by Intel Corporation or its suppliers
868a912857707864bbaaff9808717813105072a6ePatrick Benavoli * or licensors. Title to the Material remains with Intel Corporation or its
968a912857707864bbaaff9808717813105072a6ePatrick Benavoli * suppliers and licensors. The Material contains trade secrets and proprietary
1068a912857707864bbaaff9808717813105072a6ePatrick Benavoli * and confidential information of Intel or its suppliers and licensors. The
1168a912857707864bbaaff9808717813105072a6ePatrick Benavoli * Material is protected by worldwide copyright and trade secret laws and
1268a912857707864bbaaff9808717813105072a6ePatrick Benavoli * treaty provisions. No part of the Material may be used, copied, reproduced,
1368a912857707864bbaaff9808717813105072a6ePatrick Benavoli * modified, published, uploaded, posted, transmitted, distributed, or
1468a912857707864bbaaff9808717813105072a6ePatrick Benavoli * disclosed in any way without Intel’s prior express written permission.
1568a912857707864bbaaff9808717813105072a6ePatrick Benavoli *
1668a912857707864bbaaff9808717813105072a6ePatrick Benavoli * No license under any patent, copyright, trade secret or other intellectual
1768a912857707864bbaaff9808717813105072a6ePatrick Benavoli * property right is granted to or conferred upon you by disclosure or delivery
1868a912857707864bbaaff9808717813105072a6ePatrick Benavoli * of the Materials, either expressly, by implication, inducement, estoppel or
1968a912857707864bbaaff9808717813105072a6ePatrick Benavoli * otherwise. Any license under such intellectual property rights must be
2068a912857707864bbaaff9808717813105072a6ePatrick Benavoli * express and approved by Intel in writing.
2168a912857707864bbaaff9808717813105072a6ePatrick Benavoli *
2268a912857707864bbaaff9808717813105072a6ePatrick Benavoli * CREATED: 2011-06-01
2368a912857707864bbaaff9808717813105072a6ePatrick Benavoli * UPDATED: 2011-07-27
2468a912857707864bbaaff9808717813105072a6ePatrick Benavoli */
2568a912857707864bbaaff9808717813105072a6ePatrick Benavoli#pragma once
2668a912857707864bbaaff9808717813105072a6ePatrick Benavoli
2768a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include "ConfigurableElement.h"
2868a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include "Mapper.h"
2968a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include "MappingContext.h"
3068a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include <stack>
3168a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include <vector>
3268a912857707864bbaaff9808717813105072a6ePatrick Benavoli
3368a912857707864bbaaff9808717813105072a6ePatrick Benavoliclass CInstanceDefinition;
3468a912857707864bbaaff9808717813105072a6ePatrick Benavoliclass CComponentLibrary;
3568a912857707864bbaaff9808717813105072a6ePatrick Benavoliclass CSubsystemObject;
3668a912857707864bbaaff9808717813105072a6ePatrick Benavoliclass CSubsystemObjectCreator;
3768a912857707864bbaaff9808717813105072a6ePatrick Benavoli
3868a912857707864bbaaff9808717813105072a6ePatrick Benavoliclass CSubsystem : public CConfigurableElement, private IMapper
3968a912857707864bbaaff9808717813105072a6ePatrick Benavoli{
4068a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subsystem objects iterator
4168a912857707864bbaaff9808717813105072a6ePatrick Benavoli    typedef list<CSubsystemObject*>::const_iterator SubsystemObjectListIterator;
4268a912857707864bbaaff9808717813105072a6ePatrick Benavolipublic:
4368a912857707864bbaaff9808717813105072a6ePatrick Benavoli    CSubsystem(const string& strName);
4468a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual ~CSubsystem();
4568a912857707864bbaaff9808717813105072a6ePatrick Benavoli
4668a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // From IXmlSink
4768a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
4868a912857707864bbaaff9808717813105072a6ePatrick Benavoli
4968a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Susbsystem Endianness
5068a912857707864bbaaff9808717813105072a6ePatrick Benavoli    bool isBigEndian() const;
5168a912857707864bbaaff9808717813105072a6ePatrick Benavoli
52f2fd15a331fd3b5b63f0dc6f492651330adcedf9Guillaume Denneulin    // Susbsystem sanity
53f2fd15a331fd3b5b63f0dc6f492651330adcedf9Guillaume Denneulin    virtual bool isAlive() const;
54f2fd15a331fd3b5b63f0dc6f492651330adcedf9Guillaume Denneulin
55f2fd15a331fd3b5b63f0dc6f492651330adcedf9Guillaume Denneulin    // Resynchronization after subsystem restart needed
56f2fd15a331fd3b5b63f0dc6f492651330adcedf9Guillaume Denneulin    virtual bool needResync(bool bClear);
57f2fd15a331fd3b5b63f0dc6f492651330adcedf9Guillaume Denneulin
5868a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // XML configuration settings parsing
596ba361d96bc2581667b3400f87ff89fae6449e1fPatrick Benavoli    virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const;
6068a912857707864bbaaff9808717813105072a6ePatrick Benavoli
6168a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // from CElement
6268a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual string getKind() const;
6368a912857707864bbaaff9808717813105072a6ePatrick Benavoliprotected:
6468a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Parameter access
65065264a93ce9c63b6a5c95e985188ee33ba587d3Patrick Benavoli    virtual bool accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
6668a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual void logValue(string& strValue, CErrorContext& errorContext) const;
676ccab9d382c08323fb1f000d859a696f05719c92Patrick Benavoli    // Used for simulation and virtual subsystems
6868a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const;
6968a912857707864bbaaff9808717813105072a6ePatrick Benavoli
7068a912857707864bbaaff9808717813105072a6ePatrick Benavoli    /// Functionality intendedn for derived Subsystems
7168a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subsystem context mapping keys publication
7268a912857707864bbaaff9808717813105072a6ePatrick Benavoli    void addContextMappingKey(const string& strMappingKey);
7368a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subsystem object creator publication (strong reference)
746ba361d96bc2581667b3400f87ff89fae6449e1fPatrick Benavoli    void addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemObjectCreator);
7568a912857707864bbaaff9808717813105072a6ePatrick Benavoliprivate:
764ebc0984c7afe9a6f0168169d5141421b4adcc67JhinX Lee    CSubsystem(const CSubsystem&);
774ebc0984c7afe9a6f0168169d5141421b4adcc67JhinX Lee    CSubsystem& operator=(const CSubsystem&);
784ebc0984c7afe9a6f0168169d5141421b4adcc67JhinX Lee
7968a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Belonging subsystem
8068a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual const CSubsystem* getBelongingSubsystem() const;
8168a912857707864bbaaff9808717813105072a6ePatrick Benavoli
8268a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Mapping execution
8368a912857707864bbaaff9808717813105072a6ePatrick Benavoli    bool mapSubsystemElements(string& strError);
8468a912857707864bbaaff9808717813105072a6ePatrick Benavoli
853414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard    /**
863414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     * Generic subsystem mapping error handling
873414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     *
883414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     * Format an human readable error string from a key and a message in case of mapping error
893414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     *
903414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     * @param[out] strError The formated error string
913414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     * @param[in] strKey The key on which the error refers
923414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     * @param[in] strMessage The error message
933414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     * @param[in] pInstanceConfigurableElement The element on wich the error refers
943414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard     */
953414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard    void getMappingError(string& strError, const string& strKey, const string& strMessage,
963414f994f9d2bf971caa4abd03932529619a81ecKevin Rocard                         const CInstanceConfigurableElement* pInstanceConfigurableElement);
9768a912857707864bbaaff9808717813105072a6ePatrick Benavoli
98084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard    /**
99084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * Handle a configurable element mapping.
100084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     *
101084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * Add context mappings to the context and instantiate a subsystem object if needed.
102084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     *
103084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[in:out] pInstanceConfigurableElement The configurable element
104084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[out] bKeepDiving Keep diving for mapping keys
105084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard                   Is set to true if a subsystem object (tree leave) has been instantiated.
106084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard                   Undetermined on error
107084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[out] strError String filled with an human readable error on error,
108084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard                   left unmodified otherwise
109084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     *
110084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @return true on success, false on failure
111084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     */
112d3a86bf6c46db222b0afadc7899c25e1a6e015fbPatrick Benavoli    virtual bool mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError);
11368a912857707864bbaaff9808717813105072a6ePatrick Benavoli    virtual void mapEnd();
11468a912857707864bbaaff9808717813105072a6ePatrick Benavoli
11568a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Mapping generic context handling
11668a912857707864bbaaff9808717813105072a6ePatrick Benavoli    bool handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError);
117084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard
118084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard    /**
119084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * Looks if a subsystem object needs to be instantiated for the given configurable
120084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * element, then instantiate it if needed.
121084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     *
122084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[in:out] pInstanceConfigurableElement The configurable element to check
123084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     *            for instanciation
124084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[in] context The mapping values container
125084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[out] bHasCreatedSubsystemObject If a subsystem object has been instantiated.
126084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard                   Undetermined on error
127084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @param[out] strError String filled with an human readable error on error,
128084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard                   left unmodified otherwise
129084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     *
130084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     * @return true on success, false on failure
131084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard     */
132084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard    bool handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement,
133084cafba76fa5c987cdffeaaa7401202473554cbKevin Rocard                                       CMappingContext& context, bool& bHasCreatedSubsystemObject, string& strError);
13468a912857707864bbaaff9808717813105072a6ePatrick Benavoli
13568a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subsystem context mapping keys
13668a912857707864bbaaff9808717813105072a6ePatrick Benavoli    vector<string> _contextMappingKeyArray;
13768a912857707864bbaaff9808717813105072a6ePatrick Benavoli
13868a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subsystem object creator map
13968a912857707864bbaaff9808717813105072a6ePatrick Benavoli    vector<CSubsystemObjectCreator*> _subsystemObjectCreatorArray;
14068a912857707864bbaaff9808717813105072a6ePatrick Benavoli
14168a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subsystem sync objects (house keeping)
14268a912857707864bbaaff9808717813105072a6ePatrick Benavoli    list<CSubsystemObject*> _subsystemObjectList;
14368a912857707864bbaaff9808717813105072a6ePatrick Benavoli
14468a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Mapping Context stack
14568a912857707864bbaaff9808717813105072a6ePatrick Benavoli    stack<CMappingContext> _contextStack;
14668a912857707864bbaaff9808717813105072a6ePatrick Benavoli
14768a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Subelements
14868a912857707864bbaaff9808717813105072a6ePatrick Benavoli    CComponentLibrary* _pComponentLibrary;
14968a912857707864bbaaff9808717813105072a6ePatrick Benavoli    CInstanceDefinition* _pInstanceDefinition;
15068a912857707864bbaaff9808717813105072a6ePatrick Benavoli
15168a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Endianness
15268a912857707864bbaaff9808717813105072a6ePatrick Benavoli    bool _bBigEndian;
15368a912857707864bbaaff9808717813105072a6ePatrick Benavoli};
154