blob: e91a5cb7a0385fe62dd625a24cfdb793e099a287 [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"
33#include "SyncerSet.h"
34#include <list>
35#include <set>
Patrick Benavoli63499d42011-10-24 18:50:03 +020036#include <map>
Sebastien Gonzalved9526492014-02-20 22:28:03 +010037#include <string>
Patrick Benavoli68a91282011-08-31 11:23:23 +020038
39class CConfigurableElement;
40class CDomainConfiguration;
41class CParameterBlackboard;
Patrick Benavoli0bd50542011-11-29 11:10:27 +010042class CSelectionCriteriaDefinition;
Patrick Benavoli68a91282011-08-31 11:23:23 +020043
44class CConfigurableDomain : public CBinarySerializableElement
45{
Sebastien Gonzalved9526492014-02-20 22:28:03 +010046 typedef std::list<CConfigurableElement*>::const_iterator ConfigurableElementListIterator;
47 typedef std::map<const CConfigurableElement*, CSyncerSet*>::const_iterator ConfigurableElementToSyncerSetMapIterator;
Patrick Benavoli68a91282011-08-31 11:23:23 +020048public:
Sebastien Gonzalved9526492014-02-20 22:28:03 +010049 CConfigurableDomain(const std::string& strName);
Patrick Benavoli68a91282011-08-31 11:23:23 +020050 virtual ~CConfigurableDomain();
51
Patrick Benavoli63499d42011-10-24 18:50:03 +020052 // Sequence awareness
53 void setSequenceAwareness(bool bSequenceAware);
54 bool getSequenceAwareness() const;
55
Patrick Benavoli68a91282011-08-31 11:23:23 +020056 // Configuration Management
Sebastien Gonzalved9526492014-02-20 22:28:03 +010057 bool createConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError);
58 bool deleteConfiguration(const std::string& strName, std::string& strError);
59 bool renameConfiguration(const std::string& strName, const std::string& strNewName, std::string& strError);
60 bool restoreConfiguration(const std::string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list<std::string>& strError) const;
61 bool saveConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError);
62 bool setElementSequence(const std::string& strConfiguration, const std::vector<std::string>& astrNewElementSequence, std::string& strError);
63 bool getElementSequence(const std::string& strConfiguration, std::string& strResult) const;
64 bool setApplicationRule(const std::string& strConfiguration, const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError);
65 bool clearApplicationRule(const std::string& strConfiguration, std::string& strError);
66 bool getApplicationRule(const std::string& strConfiguration, std::string& strResult) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020067
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020068 // Last applied configuration name
Sebastien Gonzalved9526492014-02-20 22:28:03 +010069 std::string getLastAppliedConfigurationName() const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020070
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020071 // Pending configuration name
Sebastien Gonzalved9526492014-02-20 22:28:03 +010072 std::string getPendingConfigurationName() const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020073
Patrick Benavoli68a91282011-08-31 11:23:23 +020074 // Associated Configurable elements
Sebastien Gonzalved9526492014-02-20 22:28:03 +010075 void gatherConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const;
76 void listAssociatedToElements(std::string& strResult) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020077
78 // Configurable elements association
Sebastien Gonzalved9526492014-02-20 22:28:03 +010079 bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError);
80 bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +020081
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +010082 // Blackboard Configuration and Base Offset retrieval
Sebastien Gonzalved9526492014-02-20 22:28:03 +010083 CParameterBlackboard* findConfigurationBlackboard(const std::string& strConfiguration,
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +010084 const CConfigurableElement* pConfigurableElement,
85 uint32_t& uiBaseOffset,
86 bool& bIsLastApplied,
Sebastien Gonzalved9526492014-02-20 22:28:03 +010087 std::string& strError) const;
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +010088
Patrick Benavoli68a91282011-08-31 11:23:23 +020089 // Domain splitting
Sebastien Gonzalved9526492014-02-20 22:28:03 +010090 bool split(CConfigurableElement* pConfigurableElement, std::string& strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +020091
92 // Ensure validity on whole domain from main blackboard
93 void validate(const CParameterBlackboard* pMainBlackboard);
94
95 // Configuration application if required
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010096 void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020097
98 // Return applicable configuration validity for given configurable element
99 bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const;
100
Patrick Benavoli68a91282011-08-31 11:23:23 +0200101 // From IXmlSink
102 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
103
104 // From IXmlSource
105 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
106
107 // Class kind
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100108 virtual std::string getKind() const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200109
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100110protected:
111 // Content dumping
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100112 virtual void logValue(std::string& strValue, CErrorContext& errorContext) const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200113
Patrick Benavoli68a91282011-08-31 11:23:23 +0200114private:
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200115 // Get pending configuration
116 const CDomainConfiguration* getPendingConfiguration() const;
117
118 // Search for an applicable configuration
119 const CDomainConfiguration* findApplicableDomainConfiguration() const;
120
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121 // Returns true if children dynamic creation is to be dealt with (here, will allow child deletion upon clean)
122 virtual bool childrenAreDynamic() const;
123
124 // Ensure validity on areas related to configurable element
125 void validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard);
126
127 // Attempt validation for all configurable element's areas, relying on already existing valid configuration inside domain
128 void autoValidateAll();
129
130 // Attempt validation for one configurable element's areas, relying on already existing valid configuration inside domain
131 void autoValidateAreas(const CConfigurableElement* pConfigurableElement);
132
133 // Attempt configuration validation for all configurable elements' areas, relying on already existing valid configuration inside domain
134 bool autoValidateConfiguration(CDomainConfiguration* pDomainConfiguration);
135
136 // Search for a valid configuration for given configurable element
137 const CDomainConfiguration* findValidDomainConfiguration(const CConfigurableElement* pConfigurableElement) const;
138
Patrick Benavoli68a91282011-08-31 11:23:23 +0200139
140 // In case configurable element was removed
141 void computeSyncSet();
142
143 // Check configurable element already attached
144 bool containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const;
145
146 // Merge any descended configurable element to this one
147 void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement);
148 void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement);
149
150 // Configurable elements association
Frédéric Boisnard9620e442012-05-30 16:15:02 +0200151 void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200152 void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet);
153
154 // XML parsing
155 bool parseDomainConfigurations(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
156 bool parseConfigurableElements(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200157 bool parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200158
159 // XML composing
160 void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200161 void composeConfigurableElements(CXmlElement& xmlElement) const;
162 void composeSettings(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
163
164 // Syncer set retrieval from configurable element
165 CSyncerSet* getSyncerSet(const CConfigurableElement* pConfigurableElement) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200166
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100167 // Configuration retrieval
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100168 CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError);
169 const CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError) const;
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100170
Patrick Benavoli68a91282011-08-31 11:23:23 +0200171 // Configurable elements
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100172 std::list<CConfigurableElement*> _configurableElementList;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200173
Patrick Benavoli63499d42011-10-24 18:50:03 +0200174 // Associated syncer sets
Sebastien Gonzalved9526492014-02-20 22:28:03 +0100175 std::map<const CConfigurableElement*, CSyncerSet*> _configurableElementToSyncerSetMap;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200176
177 // Sequence awareness
178 bool _bSequenceAware;
179
Patrick Benavoli68a91282011-08-31 11:23:23 +0200180 // Syncer set used to ensure propoer synchronization of restored configurable elements
181 CSyncerSet _syncerSet;
182
183 // Last applied configuration
Patrick Benavoli63499d42011-10-24 18:50:03 +0200184 mutable const CDomainConfiguration* _pLastAppliedConfiguration;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200185};
186