1 /*
2  * 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.
29  */
30 #pragma once
31 
32 #include "Element.h"
33 
34 #include <list>
35 
36 class CConfigurableDomain;
37 class CSyncerSet;
38 class ISyncer;
39 class CSubsystem;
40 class CConfigurationAccessContext;
41 class CParameterAccessContext;
42 class CAreaConfiguration;
43 
44 class CConfigurableElement : public CElement
45 {
46     friend class CConfigurableDomain;
47     friend class CDomainConfiguration;
48     typedef std::list<const CConfigurableDomain*>::const_iterator ConfigurableDomainListConstIterator;
49 public:
50     CConfigurableElement(const std::string& strName = "");
51     virtual ~CConfigurableElement();
52 
53     // Offset in main blackboard
54     void setOffset(uint32_t uiOffset);
55     uint32_t getOffset() const;
56 
57     // Allocation
58     virtual uint32_t getFootPrint() const;
59 
60     // Syncer set (me, ascendant or descendant ones)
61     void fillSyncerSet(CSyncerSet& syncerSet) const;
62 
63     // Belonging domain
64     bool belongsTo(const CConfigurableDomain* pConfigurableDomain) const;
65 
66     // Belonging domains
67     void listBelongingDomains(std::string& strResult, bool bVertical = true) const;
68 
69     // Matching check for domain association
70     bool hasNoDomainAssociated() const;
71 
72     // Matching check for no valid associated domains
73     bool hasNoValidDomainAssociated() const;
74 
75     // Owning domains
76     void listAssociatedDomains(std::string& strResult, bool bVertical = true) const;
77     size_t getBelongingDomainCount() const;
78 
79     // Elements with no domains
80     void listRogueElements(std::string& strResult) const;
81 
82     // Belonging to no domains
83     bool isRogue() const;
84 
85     // Footprint as string
86     std::string getFootprintAsString() const;
87 
88     // Belonging subsystem
89     virtual const CSubsystem* getBelongingSubsystem() const;
90 
91     // Check element is a parameter
92     virtual bool isParameter() const;
93 
94     // AreaConfiguration creation
95     virtual CAreaConfiguration* createAreaConfiguration(const CSyncerSet* pSyncerSet) const;
96 
97     // Parameter access
98     virtual bool accessValue(CPathNavigator& pathNavigator, std::string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const;
99 
100     /**
101      * Get the list of all the ancestors that have a mapping.
102      *
103      * The mapping is represented as a std::string of all the mapping data (key:value) defined in the
104      * context of the element.
105      * In this class, the method is generic and calls its parent getListOfElementsWithMappings(...)
106      * method.
107      *
108      * @param[in:out] configurableElementPath List of all the ConfigurableElements found
109      * that have a mapping. Elements are added at the end of the list, so the root Element will be
110      * the last one.
111      *
112      */
113     virtual void getListOfElementsWithMapping(std::list<const CConfigurableElement*>&
114                                                configurableElementPath) const;
115 
116     // Used for simulation and virtual subsystems
117     virtual void setDefaultValues(CParameterAccessContext& parameterAccessContext) const;
118 
119     // Element properties
120     virtual void showProperties(std::string& strResult) const;
121 
122     // XML configuration settings parsing
123     virtual bool serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const;
124 protected:
125     // Syncer (me or ascendant)
126     virtual ISyncer* getSyncer() const;
127     // Syncer set (descendant)
128     virtual void fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const;
129     // Configuration Domain local search
130     bool containsConfigurableDomain(const CConfigurableDomain* pConfigurableDomain) const;
131 
132 private:
133     // Configurable domain association
134     void addAttachedConfigurableDomain(const CConfigurableDomain* pConfigurableDomain);
135     void removeAttachedConfigurableDomain(const CConfigurableDomain* pConfigurableDomain);
136 
137     // Belonging domain ascending search
138     bool belongsToDomainAscending(const CConfigurableDomain* pConfigurableDomain) const;
139 
140     // Belonging domains
141     void getBelongingDomains(std::list<const CConfigurableDomain*>& configurableDomainList) const;
142     void listDomains(const std::list<const CConfigurableDomain*>& configurableDomainList, std::string& strResult, bool bVertical) const;
143 
144     // Check parent is still of current type (by structure knowledge)
145     bool isOfConfigurableElementType(const CElement* pParent) const;
146 
147     // Offset in main blackboard
148     uint32_t _uiOffset;
149 
150     // Associated configurable domains
151     std::list<const CConfigurableDomain*> _configurableDomainList;
152 };
153 
154