| 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" |
| 33 | #include "SyncerSet.h" |
| 34 | #include <list> |
| 35 | #include <set> |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 36 | #include <map> |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 37 | #include <string> |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 38 | |
| 39 | class CConfigurableElement; |
| 40 | class CDomainConfiguration; |
| 41 | class CParameterBlackboard; |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 42 | class CSelectionCriteriaDefinition; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 43 | |
| 44 | class CConfigurableDomain : public CBinarySerializableElement |
| 45 | { |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 46 | typedef std::list<CConfigurableElement*>::const_iterator ConfigurableElementListIterator; |
| 47 | typedef std::map<const CConfigurableElement*, CSyncerSet*>::const_iterator ConfigurableElementToSyncerSetMapIterator; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 48 | public: |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 49 | CConfigurableDomain(const std::string& strName); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 50 | virtual ~CConfigurableDomain(); |
| 51 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 52 | // Sequence awareness |
| 53 | void setSequenceAwareness(bool bSequenceAware); |
| 54 | bool getSequenceAwareness() const; |
| 55 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 56 | // Configuration Management |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 57 | 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 67 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 68 | // Last applied configuration name |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 69 | std::string getLastAppliedConfigurationName() const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 70 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 71 | // Pending configuration name |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 72 | std::string getPendingConfigurationName() const; |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 73 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 74 | // Associated Configurable elements |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 75 | void gatherConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const; |
| 76 | void listAssociatedToElements(std::string& strResult) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 77 | |
| 78 | // Configurable elements association |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 79 | bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError); |
| 80 | bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 81 | |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 82 | // Blackboard Configuration and Base Offset retrieval |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 83 | CParameterBlackboard* findConfigurationBlackboard(const std::string& strConfiguration, |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 84 | const CConfigurableElement* pConfigurableElement, |
| 85 | uint32_t& uiBaseOffset, |
| 86 | bool& bIsLastApplied, |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 87 | std::string& strError) const; |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 88 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 89 | // Domain splitting |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 90 | bool split(CConfigurableElement* pConfigurableElement, std::string& strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 91 | |
| 92 | // Ensure validity on whole domain from main blackboard |
| 93 | void validate(const CParameterBlackboard* pMainBlackboard); |
| 94 | |
| 95 | // Configuration application if required |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 96 | void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 97 | |
| 98 | // Return applicable configuration validity for given configurable element |
| 99 | bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const; |
| 100 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 101 | // 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 Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 108 | virtual std::string getKind() const; |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 109 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 110 | protected: |
| 111 | // Content dumping |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 112 | virtual void logValue(std::string& strValue, CErrorContext& errorContext) const; |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 113 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 114 | private: |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 115 | // Get pending configuration |
| 116 | const CDomainConfiguration* getPendingConfiguration() const; |
| 117 | |
| 118 | // Search for an applicable configuration |
| 119 | const CDomainConfiguration* findApplicableDomainConfiguration() const; |
| 120 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 121 | // 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 139 | |
| 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 Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 151 | void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 152 | 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 Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 157 | bool parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 158 | |
| 159 | // XML composing |
| 160 | void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 161 | 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 166 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 167 | // Configuration retrieval |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 168 | CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError); |
| 169 | const CDomainConfiguration* findConfiguration(const std::string& strConfiguration, std::string& strError) const; |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 170 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 171 | // Configurable elements |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 172 | std::list<CConfigurableElement*> _configurableElementList; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 173 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 174 | // Associated syncer sets |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame^] | 175 | std::map<const CConfigurableElement*, CSyncerSet*> _configurableElementToSyncerSetMap; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 176 | |
| 177 | // Sequence awareness |
| 178 | bool _bSequenceAware; |
| 179 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 180 | // Syncer set used to ensure propoer synchronization of restored configurable elements |
| 181 | CSyncerSet _syncerSet; |
| 182 | |
| 183 | // Last applied configuration |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 184 | mutable const CDomainConfiguration* _pLastAppliedConfiguration; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 185 | }; |
| 186 | |