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 "BinarySerializableElement.h"
33 #include <list>
34 #include <string>
35 
36 class CConfigurableElement;
37 class CAreaConfiguration;
38 class CParameterBlackboard;
39 class CConfigurationAccessContext;
40 class CCompoundRule;
41 class CSyncerSet;
42 class CSelectionCriteriaDefinition;
43 
44 class CDomainConfiguration : public CBinarySerializableElement
45 {
46     enum ChildElementType {
47         ECompoundRule
48     };
49     typedef std::list<CAreaConfiguration*>::const_iterator AreaConfigurationListIterator;
50 public:
51     CDomainConfiguration(const std::string& strName);
52     virtual ~CDomainConfiguration();
53 
54     // Configurable Elements association
55     void addConfigurableElement(const CConfigurableElement* pConfigurableElement, const CSyncerSet* pSyncerSet);
56     void removeConfigurableElement(const CConfigurableElement* pConfigurableElement);
57 
58     // Sequence management
59     bool setElementSequence(const std::vector<std::string>& astrNewElementSequence, std::string& strError);
60     void getElementSequence(std::string& strResult) const;
61 
62     // Application rule
63     bool setApplicationRule(const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError);
64     void clearApplicationRule();
65     void getApplicationRule(std::string& strResult) const;
66 
67     // Get Blackboard for an element of the domain
68     CParameterBlackboard* getBlackboard(const CConfigurableElement* pConfigurableElement) const;
69 
70     // Save data from current
71     void save(const CParameterBlackboard* pMainBlackboard);
72     // Apply data to current
73     bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list<std::string>* plstrError = NULL) const;
74     // Ensure validity for configurable element area configuration
75     void validate(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard);
76     // Ensure validity of all area configurations
77     void validate(const CParameterBlackboard* pMainBlackboard);
78     // Return configuration validity for given configurable element
79     bool isValid(const CConfigurableElement* pConfigurableElement) const;
80     // Ensure validity of configurable element's area configuration by copying in from a valid one
81     void validateAgainst(const CDomainConfiguration* pValidDomainConfiguration, const CConfigurableElement* pConfigurableElement);
82     // Ensure validity of all configurable element's area configuration by copying in from a valid ones
83     void validateAgainst(const CDomainConfiguration* pValidDomainConfiguration);
84     // Applicability checking
85     bool isApplicable() const;
86     // Merge existing configurations to given configurable element ones
87     void merge(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement);
88     // Domain splitting
89     void split(CConfigurableElement* pFromConfigurableElement);
90 
91     // XML configuration settings parsing/composing
92     bool parseSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext);
93     void composeSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext) const;
94 
95     // Serialization
96     virtual void binarySerialize(CBinaryStream& binaryStream);
97 
98     // Data size
99     virtual size_t getDataSize() const;
100 
101     // Class kind
102     virtual std::string getKind() const;
103 
104 private:
105     // Returns true if children dynamic creation is to be dealt with (here, will allow child deletion upon clean)
106     virtual bool childrenAreDynamic() const;
107     // XML configuration settings serializing
108     bool serializeConfigurableElementSettings(CAreaConfiguration* pAreaConfiguration, CXmlElement& xmlConfigurableElementSettingsElement, CXmlSerializingContext& serializingContext, bool bSerializeOut);
109     // AreaConfiguration retrieval from configurable element
110     CAreaConfiguration* getAreaConfiguration(const CConfigurableElement* pConfigurableElement) const;
111     // AreaConfiguration retrieval from present area configurations
112     CAreaConfiguration* findAreaConfiguration(const std::string& strConfigurableElementPath) const;
113     // AreaConfiguration retrieval from given area configuration std::list
114     CAreaConfiguration* findAreaConfiguration(const std::string& strConfigurableElementPath, const std::list<CAreaConfiguration*>& areaConfigurationList) const;
115     // Area configuration ordering
116     void reorderAreaConfigurations(const std::list<CAreaConfiguration*>& areaConfigurationList);
117     // Find area configuration rank from regular std::list: for ordered std::list maintainance
118     uint32_t getAreaConfigurationRank(const CAreaConfiguration* pAreaConfiguration) const;
119     // Find area configuration from regular std::list based on rank: for ordered std::list maintainance
120     CAreaConfiguration* getAreaConfiguration(uint32_t uiAreaConfigurationRank) const;
121 
122     // Rule
123     const CCompoundRule* getRule() const;
124     CCompoundRule* getRule();
125     void setRule(CCompoundRule* pRule);
126 
127     // AreaConfigurations
128     std::list<CAreaConfiguration*> _areaConfigurationList;
129     std::list<CAreaConfiguration*> _orderedAreaConfigurationList;
130 };
131