blob: 084c1878b2aa7a9c68397ada9f363a382592d710 [file] [log] [blame]
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001/*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * 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.
Patrick Benavoli68a91282011-08-31 11:23:23 +020029 */
30#pragma once
31
32#include "BinarySerializableElement.h"
David Wagner29fa61f2014-12-19 11:15:02 +010033#include "XmlSerializingContext.h"
34#include "XmlDomainImportContext.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020035#include "SyncerSet.h"
36#include <list>
37#include <set>
Patrick Benavoli63499d42011-10-24 18:50:03 +020038#include <map>
Sebastien Gonzalved9526492014-02-20 22:28:03 +010039#include <string>
Patrick Benavoli68a91282011-08-31 11:23:23 +020040
41class CConfigurableElement;
42class CDomainConfiguration;
43class CParameterBlackboard;
Patrick Benavoli0bd50542011-11-29 11:10:27 +010044class CSelectionCriteriaDefinition;
Patrick Benavoli68a91282011-08-31 11:23:23 +020045
46class CConfigurableDomain : public CBinarySerializableElement
47{
Sebastien Gonzalved9526492014-02-20 22:28:03 +010048 typedef std::list<CConfigurableElement*>::const_iterator ConfigurableElementListIterator;
49 typedef std::map<const CConfigurableElement*, CSyncerSet*>::const_iterator ConfigurableElementToSyncerSetMapIterator;
Patrick Benavoli68a91282011-08-31 11:23:23 +020050public:
Sebastien Gonzalved9526492014-02-20 22:28:03 +010051 CConfigurableDomain(const std::string& strName);
Patrick Benavoli68a91282011-08-31 11:23:23 +020052 virtual ~CConfigurableDomain();
53
Patrick Benavoli63499d42011-10-24 18:50:03 +020054 // Sequence awareness
55 void setSequenceAwareness(bool bSequenceAware);
56 bool getSequenceAwareness() const;
57
Patrick Benavoli68a91282011-08-31 11:23:23 +020058 // Configuration Management
Sebastien Gonzalved9526492014-02-20 22:28:03 +010059 bool createConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError);
60 bool deleteConfiguration(const std::string& strName, std::string& strError);
61 bool renameConfiguration(const std::string& strName, const std::string& strNewName, std::string& strError);
62 bool restoreConfiguration(const std::string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list<std::string>& strError) const;
63 bool saveConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError);
64 bool setElementSequence(const std::string& strConfiguration, const std::vector<std::string>& astrNewElementSequence, std::string& strError);
65 bool getElementSequence(const std::string& strConfiguration, std::string& strResult) const;
66 bool setApplicationRule(const std::string& strConfiguration, const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError);
67 bool clearApplicationRule(const std::string& strConfiguration, std::string& strError);
68 bool getApplicationRule(const std::string& strConfiguration, std::string& strResult) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020069
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020070 // Last applied configuration name
Sebastien Gonzalved9526492014-02-20 22:28:03 +010071 std::string getLastAppliedConfigurationName() const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020072
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020073 // Pending configuration name
Sebastien Gonzalved9526492014-02-20 22:28:03 +010074 std::string getPendingConfigurationName() const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020075
Patrick Benavoli68a91282011-08-31 11:23:23 +020076 // Associated Configurable elements
Sebastien Gonzalved9526492014-02-20 22:28:03 +010077 void gatherConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const;
78 void listAssociatedToElements(std::string& strResult) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020079
80 // Configurable elements association
Sebastien Gonzalved9526492014-02-20 22:28:03 +010081 bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError);
82 bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +020083
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +010084 // Blackboard Configuration and Base Offset retrieval
Sebastien Gonzalved9526492014-02-20 22:28:03 +010085 CParameterBlackboard* findConfigurationBlackboard(const std::string& strConfiguration,
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +010086 const CConfigurableElement* pConfigurableElement,
87 uint32_t& uiBaseOffset,
88 bool& bIsLastApplied,
Sebastien Gonzalved9526492014-02-20 22:28:03 +010089 std::string& strError) const;
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +010090
Patrick Benavoli68a91282011-08-31 11:23:23 +020091 // Domain splitting
Sebastien Gonzalved9526492014-02-20 22:28:03 +010092 bool split(CConfigurableElement* pConfigurableElement, std::string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +020093
94 // Ensure validity on whole domain from main blackboard
95 void validate(const CParameterBlackboard* pMainBlackboard);
96
97 // Configuration application if required
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010098 void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020099
100 // Return applicable configuration validity for given configurable element
101 bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const;
102
Patrick Benavoli68a91282011-08-31 11:23:23 +0200103 // From IXmlSink
104 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
105
106 // From IXmlSource
107 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
David Wagner8cb5d882014-12-09 15:26:06 +0100108 virtual void childrenToXml(CXmlElement& xmlElement,
109 CXmlSerializingContext& serializingContext) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200110
111 // Class kind
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100112 virtual std::string getKind() const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200113
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100114protected:
115 // Content dumping
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100116 virtual void logValue(std::string& strValue, CErrorContext& errorContext) const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200117
Patrick Benavoli68a91282011-08-31 11:23:23 +0200118private:
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200119 // Get pending configuration
120 const CDomainConfiguration* getPendingConfiguration() const;
121
122 // Search for an applicable configuration
123 const CDomainConfiguration* findApplicableDomainConfiguration() const;
124
Patrick Benavoli68a91282011-08-31 11:23:23 +0200125 // Returns true if children dynamic creation is to be dealt with (here, will allow child deletion upon clean)
126 virtual bool childrenAreDynamic() const;
127
128 // Ensure validity on areas related to configurable element
129 void validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard);
130
131 // Attempt validation for all configurable element's areas, relying on already existing valid configuration inside domain
132 void autoValidateAll();
133
134 // Attempt validation for one configurable element's areas, relying on already existing valid configuration inside domain
135 void autoValidateAreas(const CConfigurableElement* pConfigurableElement);
136
137 // Attempt configuration validation for all configurable elements' areas, relying on already existing valid configuration inside domain
138 bool autoValidateConfiguration(CDomainConfiguration* pDomainConfiguration);
139
140 // Search for a valid configuration for given configurable element
141 const CDomainConfiguration* findValidDomainConfiguration(const CConfigurableElement* pConfigurableElement) const;
142
Patrick Benavoli68a91282011-08-31 11:23:23 +0200143
144 // In case configurable element was removed
145 void computeSyncSet();
146
147 // Check configurable element already attached
148 bool containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const;
149
150 // Merge any descended configurable element to this one
151 void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement);
152 void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement);
153
154 // Configurable elements association
Frédéric Boisnard9620e442012-05-30 16:15:02 +0200155 void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200156 void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet);
157
158 // XML parsing
David Wagner29fa61f2014-12-19 11:15:02 +0100159 /**
160 * Deserialize domain configurations from an Xml document and add them to
161 * the domain.
162 *
163 * @param[in] xmlElement the XML element to be parsed
164 * @param[in] serializingContext context for the deserialization
165 *
166 * @return false if an error occurs, true otherwise.
167 */
168 bool parseDomainConfigurations(const CXmlElement& xmlElement,
169 CXmlDomainImportContext& serializingContext);
170 /**
171 * Deserialize domain elements from an Xml document and add them to
172 * the domain.
173 *
174 * @param[in] xmlElement the XML element to be parsed
175 * @param[in] serializingContext context for the deserialization
176 *
177 * @return false if an error occurs, true otherwise.
178 */
179 bool parseConfigurableElements(const CXmlElement& xmlElement,
180 CXmlDomainImportContext& serializingContext);
181 /**
182 * Deserialize settings from an Xml document and add them to
183 * the domain.
184 *
185 * @param[in] xmlElement the XML element to be parsed
186 * @param[in] xmlDomainImportContext context for the deserialization
187 *
188 * @return false if an error occurs, true otherwise.
189 */
190 bool parseSettings(const CXmlElement& xmlElement,
191 CXmlDomainImportContext& serializingContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200192
193 // XML composing
194 void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200195 void composeConfigurableElements(CXmlElement& xmlElement) const;
196 void composeSettings(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
197
198 // Syncer set retrieval from configurable element
199 CSyncerSet* getSyncerSet(const CConfigurableElement* pConfigurableElement) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200200
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100201 // Configuration retrieval
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100202 CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError);
203 const CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError) const;
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100204
Patrick Benavoli68a91282011-08-31 11:23:23 +0200205 // Configurable elements
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100206 std::list<CConfigurableElement*> _configurableElementList;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200207
Patrick Benavoli63499d42011-10-24 18:50:03 +0200208 // Associated syncer sets
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100209 std::map<const CConfigurableElement*, CSyncerSet*> _configurableElementToSyncerSetMap;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200210
211 // Sequence awareness
212 bool _bSequenceAware;
213
Patrick Benavoli68a91282011-08-31 11:23:23 +0200214 // Syncer set used to ensure propoer synchronization of restored configurable elements
215 CSyncerSet _syncerSet;
216
217 // Last applied configuration
Patrick Benavoli63499d42011-10-24 18:50:03 +0200218 mutable const CDomainConfiguration* _pLastAppliedConfiguration;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200219};
220