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 <set>
34 #include <list>
35 #include <string>
36 
37 
38 class CParameterBlackboard;
39 class CConfigurableElement;
40 class CSyncerSet;
41 class CConfigurableDomain;
42 class CSelectionCriteriaDefinition;
43 
44 class CConfigurableDomains : public CBinarySerializableElement
45 {
46 public:
47     CConfigurableDomains();
48 
49     // Configuration/Domains handling
50     /// Domains
51     bool createDomain(const std::string& strName, std::string& strError);
52 
53     /*
54      * Adds a domain object to configurable domains. The ConfigurableDomains
55      * object takes ownership of the ConfigurableDomain object.
56      *
57      * @param[in] pDomain the domain object.
58      * @param[in] bOverwrite if false, will refuse to overwrite an existing
59      * domain, otherwise, an existing domain with the same name will first be
60      * removed.
61      * @param[in,out] strError error message
62      *
63      * @returns true if the domain was successfully added
64      */
65     bool addDomain(CConfigurableDomain& domain, bool bOverwrite, std::string& strError);
66 
67     /**
68      * Delete a domain by name
69      *
70      * @param[in] strName name of the domain to be deleted
71      * @param[in,out] strError error message
72      *
73      * @returns true of the domain was sucessfully deleted, false otherwise (i.e.
74      * the domain didn't exist).
75      */
76     bool deleteDomain(const std::string& strName, std::string& strError);
77     void deleteAllDomains();
78     bool renameDomain(const std::string& strName, const std::string& strNewName, std::string& strError);
79     bool setSequenceAwareness(const std::string& strDomain, bool bSequenceAware, std::string& strError);
80     bool getSequenceAwareness(const std::string& strDomain, bool& bSequenceAware, std::string& strError) const;
81     bool listDomainElements(const std::string& strDomain, std::string& strResult) const;
82     bool split(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError);
83     void listAssociatedElements(std::string& strResult) const;
84     void listConflictingElements(std::string& strResult) const;
85     void listDomains(std::string& strResult) const;
86     /// Configurations
87     bool listConfigurations(const std::string& strDomain, std::string& strResult) const;
88     bool createConfiguration(const std::string& strDomain, const std::string& strConfiguration, const CParameterBlackboard* pMainBlackboard, std::string& strError);
89     bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError);
90     bool renameConfiguration(const std::string& strDomain, const std::string& strConfigurationName, const std::string& strNewConfigurationName, std::string& strError);
91     bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list<std::string>& lstrError) const;
92     bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, const CParameterBlackboard* pMainBlackboard, std::string& strError);
93     bool setElementSequence(const std::string& strDomain, const std::string& strConfiguration, const std::vector<std::string>& astrNewElementSequence, std::string& strError);
94     bool getElementSequence(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult) const;
95     bool setApplicationRule(const std::string& strDomain, const std::string& strConfiguration, const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError);
96     bool clearApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strError);
97     bool getApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult) const;
98 
99     // Last applied configurations
100     void listLastAppliedConfigurations(std::string& strResult) const;
101 
102     // Configurable element - domain association
103     bool addConfigurableElementToDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError);
104     bool removeConfigurableElementFromDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError);
105 
106     // Configuration Blackboard for element
107     CParameterBlackboard* findConfigurationBlackboard(const std::string& strDomain,
108                                      const std::string& strConfiguration,
109                                      const CConfigurableElement* pConfigurableElement,
110                                      uint32_t& uiBaseOffset,
111                                      bool& bIsLastApplied,
112                                      std::string& strError) const;
113 
114     const CConfigurableDomain* findConfigurableDomain(const std::string& strDomain,
115                                                       std::string& strError) const;
116 
117     // Binary settings load/store
118     bool serializeSettings(const std::string& strBinarySettingsFilePath, bool bOut, uint8_t uiStructureChecksum, std::string& strError);
119 
120     // From IXmlSource
121     virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
122 
123     // Ensure validity on whole domains from main blackboard
124     void validate(const CParameterBlackboard* pMainBlackboard);
125 
126     // Configuration application if required
127     void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const;
128 
129     // Class kind
130     virtual std::string getKind() const;
131 private:
132     /** Delete a domain
133      *
134      * @param(in] configurableDomain domain to be deleted
135      * @param[in,out] strError error message
136      * @returns true of the domain was sucessfully deleted, false otherwise (i.e.
137      * the domain didn't exist).
138      */
139     void deleteDomain(CConfigurableDomain& configurableDomain);
140     // Returns true if children dynamic creation is to be dealt with
141     virtual bool childrenAreDynamic() const;
142     // Gather owned configurable elements owned by any domain
143     void gatherAllOwnedConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const;
144     // Domain retrieval
145     CConfigurableDomain* findConfigurableDomain(const std::string& strDomain, std::string& strError);
146 };
147 
148