| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 1 | /* |
| David Wagner | b76c9d6 | 2014-02-05 18:30:24 +0100 | [diff] [blame] | 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. |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 29 | */ |
| 30 | #pragma once |
| 31 | |
| 32 | #include "BinarySerializableElement.h" |
| David Wagner | 29fa61f | 2014-12-19 11:15:02 +0100 | [diff] [blame^] | 33 | #include "XmlSerializingContext.h" |
| 34 | #include "XmlDomainImportContext.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 35 | #include "SyncerSet.h" |
| 36 | #include <list> |
| 37 | #include <set> |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 38 | #include <map> |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 39 | #include <string> |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 40 | |
| 41 | class CConfigurableElement; |
| 42 | class CDomainConfiguration; |
| 43 | class CParameterBlackboard; |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 44 | class CSelectionCriteriaDefinition; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 45 | |
| 46 | class CConfigurableDomain : public CBinarySerializableElement |
| 47 | { |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 48 | typedef std::list<CConfigurableElement*>::const_iterator ConfigurableElementListIterator; |
| 49 | typedef std::map<const CConfigurableElement*, CSyncerSet*>::const_iterator ConfigurableElementToSyncerSetMapIterator; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 50 | public: |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 51 | CConfigurableDomain(const std::string& strName); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 52 | virtual ~CConfigurableDomain(); |
| 53 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 54 | // Sequence awareness |
| 55 | void setSequenceAwareness(bool bSequenceAware); |
| 56 | bool getSequenceAwareness() const; |
| 57 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 58 | // Configuration Management |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 59 | 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 69 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 70 | // Last applied configuration name |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 71 | std::string getLastAppliedConfigurationName() const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 72 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 73 | // Pending configuration name |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 74 | std::string getPendingConfigurationName() const; |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 75 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 76 | // Associated Configurable elements |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 77 | void gatherConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const; |
| 78 | void listAssociatedToElements(std::string& strResult) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 79 | |
| 80 | // Configurable elements association |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 81 | bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError); |
| 82 | bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 83 | |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 84 | // Blackboard Configuration and Base Offset retrieval |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 85 | CParameterBlackboard* findConfigurationBlackboard(const std::string& strConfiguration, |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 86 | const CConfigurableElement* pConfigurableElement, |
| 87 | uint32_t& uiBaseOffset, |
| 88 | bool& bIsLastApplied, |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 89 | std::string& strError) const; |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 90 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 91 | // Domain splitting |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 92 | bool split(CConfigurableElement* pConfigurableElement, std::string& strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 93 | |
| 94 | // Ensure validity on whole domain from main blackboard |
| 95 | void validate(const CParameterBlackboard* pMainBlackboard); |
| 96 | |
| 97 | // Configuration application if required |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 98 | void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 99 | |
| 100 | // Return applicable configuration validity for given configurable element |
| 101 | bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const; |
| 102 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 103 | // 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 Wagner | 8cb5d88 | 2014-12-09 15:26:06 +0100 | [diff] [blame] | 108 | virtual void childrenToXml(CXmlElement& xmlElement, |
| 109 | CXmlSerializingContext& serializingContext) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 110 | |
| 111 | // Class kind |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 112 | virtual std::string getKind() const; |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 113 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 114 | protected: |
| 115 | // Content dumping |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 116 | virtual void logValue(std::string& strValue, CErrorContext& errorContext) const; |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 117 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 118 | private: |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 119 | // Get pending configuration |
| 120 | const CDomainConfiguration* getPendingConfiguration() const; |
| 121 | |
| 122 | // Search for an applicable configuration |
| 123 | const CDomainConfiguration* findApplicableDomainConfiguration() const; |
| 124 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 125 | // 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 143 | |
| 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 Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 155 | void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 156 | void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); |
| 157 | |
| 158 | // XML parsing |
| David Wagner | 29fa61f | 2014-12-19 11:15:02 +0100 | [diff] [blame^] | 159 | /** |
| 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 192 | |
| 193 | // XML composing |
| 194 | void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 195 | 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 200 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 201 | // Configuration retrieval |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 202 | CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError); |
| 203 | const CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError) const; |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 204 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 205 | // Configurable elements |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 206 | std::list<CConfigurableElement*> _configurableElementList; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 207 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 208 | // Associated syncer sets |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 209 | std::map<const CConfigurableElement*, CSyncerSet*> _configurableElementToSyncerSetMap; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 210 | |
| 211 | // Sequence awareness |
| 212 | bool _bSequenceAware; |
| 213 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 214 | // Syncer set used to ensure propoer synchronization of restored configurable elements |
| 215 | CSyncerSet _syncerSet; |
| 216 | |
| 217 | // Last applied configuration |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 218 | mutable const CDomainConfiguration* _pLastAppliedConfiguration; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 219 | }; |
| 220 | |