• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2011-2015, 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 "AreaConfiguration.h"
33 #include "XmlDomainImportContext.h"
34 #include "XmlDomainExportContext.h"
35 #include "Element.h"
36 #include "Results.h"
37 #include <list>
38 #include <string>
39 #include <memory>
40 
41 class CConfigurableElement;
42 class CParameterBlackboard;
43 class CConfigurationAccessContext;
44 class CCompoundRule;
45 class CSyncerSet;
46 class CSelectionCriteriaDefinition;
47 
48 class CDomainConfiguration : public CElement
49 {
50     enum ChildElementType
51     {
52         ECompoundRule
53     };
54 
55 public:
56     CDomainConfiguration(const std::string &strName);
57 
58     // Configurable Elements association
59     void addConfigurableElement(const CConfigurableElement *configurableElement,
60                                 const CSyncerSet *syncerSet);
61     void removeConfigurableElement(const CConfigurableElement *pConfigurableElement);
62 
63     /**
64      * Sequence management: Prepend provided elements into internal list in the same order than
65      * they appear in the sequence of element path.
66      * @param[in] newElementSequence sequence of path of new element
67      * @param[out] error human readable error
68      * @return true if the new sequence has been taken into account, false otherwise and error is
69      * set accordingly.
70      */
71     bool setElementSequence(const std::vector<std::string> &newElementSequence, std::string &error);
72     void getElementSequence(std::string &strResult) const;
73 
74     // Application rule
75     bool setApplicationRule(const std::string &strApplicationRule,
76                             const CSelectionCriteriaDefinition *pSelectionCriteriaDefinition,
77                             std::string &strError);
78     void clearApplicationRule();
79     std::string getApplicationRule() const;
80 
81     // Get Blackboard for an element of the domain
82     CParameterBlackboard *getBlackboard(const CConfigurableElement *pConfigurableElement) const;
83 
84     // Save data from current
85     void save(const CParameterBlackboard *pMainBlackboard);
86 
87     /** Restore the configuration
88      *
89      * @param[in] pMainBlackboard the application main blackboard
90      * @param[in] bSync indicates if a synchronisation has to be done
91      * @param[out] errors, errors encountered during restoration
92      * @return true if success false otherwise
93      */
94     bool restore(CParameterBlackboard *pMainBlackboard, bool bSync,
95                  core::Results *errors = NULL) const;
96 
97     // Ensure validity for configurable element area configuration
98     void validate(const CConfigurableElement *pConfigurableElement,
99                   const CParameterBlackboard *pMainBlackboard);
100     // Ensure validity of all area configurations
101     void validate(const CParameterBlackboard *pMainBlackboard);
102     // Return configuration validity for given configurable element
103     bool isValid(const CConfigurableElement *pConfigurableElement) const;
104     // Ensure validity of configurable element's area configuration by copying in from a valid one
105     void validateAgainst(const CDomainConfiguration *pValidDomainConfiguration,
106                          const CConfigurableElement *pConfigurableElement);
107     // Ensure validity of all configurable element's area configuration by copying in from a valid
108     // ones
109     void validateAgainst(const CDomainConfiguration *validDomainConfiguration);
110     // Applicability checking
111     bool isApplicable() const;
112     // Merge existing configurations to given configurable element ones
113     void merge(CConfigurableElement *pToConfigurableElement,
114                CConfigurableElement *pFromConfigurableElement);
115     // Domain splitting
116     void split(CConfigurableElement *pFromConfigurableElement);
117 
118     // XML configuration settings parsing/composing
119     bool parseSettings(CXmlElement &xmlConfigurationSettingsElement,
120                        CXmlDomainImportContext &context);
121     void composeSettings(CXmlElement &xmlConfigurationSettingsElement,
122                          CXmlDomainExportContext &context) const;
123 
124     // Class kind
125     virtual std::string getKind() const;
126 
127 private:
128     using AreaConfiguration = std::unique_ptr<CAreaConfiguration>;
129     using AreaConfigurations = std::list<AreaConfiguration>;
130 
131     // Returns true if children dynamic creation is to be dealt with (here, will allow child
132     // deletion upon clean)
133     virtual bool childrenAreDynamic() const;
134     // XML configuration settings serializing
135     bool importOneConfigurableElementSettings(CAreaConfiguration *areaConfiguration,
136                                               CXmlElement &xmlConfigurableElementSettingsElement,
137                                               CXmlDomainImportContext &context);
138     bool exportOneConfigurableElementSettings(CAreaConfiguration *areaConfiguration,
139                                               CXmlElement &xmlConfigurableElementSettingsElement,
140                                               CXmlDomainExportContext &context) const;
141     // AreaConfiguration retrieval from configurable element
142     const AreaConfiguration &getAreaConfiguration(
143         const CConfigurableElement *pConfigurableElement) const;
144 
145     /**
146      * Returns the AreaConfiguration iterator associated to the Element refered by its path
147      * @param[in] configurableElementPath to check if found in current list of areaconfigurations
148      * @return iterator on the configuration associated to the Element with the given path,
149      *                  last if not found
150      */
151     AreaConfigurations::iterator findAreaConfigurationByPath(
152         const std::string &configurableElementPath);
153 
154     // Rule
155     const CCompoundRule *getRule() const;
156     CCompoundRule *getRule();
157     void setRule(CCompoundRule *pRule);
158 
159     AreaConfigurations mAreaConfigurationList;
160 };
161