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> |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 37 | |
| 38 | class CConfigurableElement; |
| 39 | class CDomainConfiguration; |
| 40 | class CParameterBlackboard; |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 41 | class CSelectionCriteriaDefinition; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 42 | |
| 43 | class CConfigurableDomain : public CBinarySerializableElement |
| 44 | { |
| 45 | typedef list<CConfigurableElement*>::const_iterator ConfigurableElementListIterator; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 46 | typedef map<const CConfigurableElement*, CSyncerSet*>::const_iterator ConfigurableElementToSyncerSetMapIterator; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 47 | public: |
| 48 | CConfigurableDomain(const string& strName); |
| 49 | virtual ~CConfigurableDomain(); |
| 50 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 51 | // Sequence awareness |
| 52 | void setSequenceAwareness(bool bSequenceAware); |
| 53 | bool getSequenceAwareness() const; |
| 54 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 55 | // Configuration Management |
| 56 | bool createConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError); |
| 57 | bool deleteConfiguration(const string& strName, string& strError); |
| 58 | bool renameConfiguration(const string& strName, const string& strNewName, string& strError); |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 59 | bool restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, list<string>& strError) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 60 | bool saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError); |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 61 | bool setElementSequence(const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError); |
| 62 | bool getElementSequence(const string& strConfiguration, string& strResult) const; |
| 63 | bool setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError); |
| 64 | bool clearApplicationRule(const string& strConfiguration, string& strError); |
| 65 | bool getApplicationRule(const string& strConfiguration, string& strResult) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 66 | |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 67 | // Last applied configuration name |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 68 | string getLastAppliedConfigurationName() const; |
| 69 | |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 70 | // Pending configuration name |
| 71 | string getPendingConfigurationName() const; |
| 72 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 73 | // Associated Configurable elements |
| 74 | void gatherConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const; |
| 75 | void listAssociatedToElements(string& strResult) const; |
| 76 | |
| 77 | // Configurable elements association |
| 78 | bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError); |
| 79 | bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, string& strError); |
| 80 | |
Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 81 | // Blackboard Configuration and Base Offset retrieval |
| 82 | CParameterBlackboard* findConfigurationBlackboard(const string& strConfiguration, |
| 83 | const CConfigurableElement* pConfigurableElement, |
| 84 | uint32_t& uiBaseOffset, |
| 85 | bool& bIsLastApplied, |
| 86 | string& strError) const; |
| 87 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 88 | // Domain splitting |
| 89 | bool split(CConfigurableElement* pConfigurableElement, string& strError); |
| 90 | |
| 91 | // Ensure validity on whole domain from main blackboard |
| 92 | void validate(const CParameterBlackboard* pMainBlackboard); |
| 93 | |
| 94 | // Configuration application if required |
Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 95 | void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 96 | |
| 97 | // Return applicable configuration validity for given configurable element |
| 98 | bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const; |
| 99 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 100 | // From IXmlSink |
| 101 | virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); |
| 102 | |
| 103 | // From IXmlSource |
| 104 | virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; |
| 105 | |
| 106 | // Class kind |
| 107 | virtual string getKind() const; |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 108 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 109 | protected: |
| 110 | // Content dumping |
| 111 | virtual void logValue(string& strValue, CErrorContext& errorContext) const; |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 112 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 113 | private: |
Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 114 | // Get pending configuration |
| 115 | const CDomainConfiguration* getPendingConfiguration() const; |
| 116 | |
| 117 | // Search for an applicable configuration |
| 118 | const CDomainConfiguration* findApplicableDomainConfiguration() const; |
| 119 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 120 | // Returns true if children dynamic creation is to be dealt with (here, will allow child deletion upon clean) |
| 121 | virtual bool childrenAreDynamic() const; |
| 122 | |
| 123 | // Ensure validity on areas related to configurable element |
| 124 | void validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard); |
| 125 | |
| 126 | // Attempt validation for all configurable element's areas, relying on already existing valid configuration inside domain |
| 127 | void autoValidateAll(); |
| 128 | |
| 129 | // Attempt validation for one configurable element's areas, relying on already existing valid configuration inside domain |
| 130 | void autoValidateAreas(const CConfigurableElement* pConfigurableElement); |
| 131 | |
| 132 | // Attempt configuration validation for all configurable elements' areas, relying on already existing valid configuration inside domain |
| 133 | bool autoValidateConfiguration(CDomainConfiguration* pDomainConfiguration); |
| 134 | |
| 135 | // Search for a valid configuration for given configurable element |
| 136 | const CDomainConfiguration* findValidDomainConfiguration(const CConfigurableElement* pConfigurableElement) const; |
| 137 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 138 | |
| 139 | // In case configurable element was removed |
| 140 | void computeSyncSet(); |
| 141 | |
| 142 | // Check configurable element already attached |
| 143 | bool containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const; |
| 144 | |
| 145 | // Merge any descended configurable element to this one |
| 146 | void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement); |
| 147 | void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement); |
| 148 | |
| 149 | // Configurable elements association |
Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 150 | void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 151 | void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); |
| 152 | |
| 153 | // XML parsing |
| 154 | bool parseDomainConfigurations(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); |
| 155 | bool parseConfigurableElements(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 156 | bool parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 157 | |
| 158 | // XML composing |
| 159 | void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 160 | void composeConfigurableElements(CXmlElement& xmlElement) const; |
| 161 | void composeSettings(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; |
| 162 | |
| 163 | // Syncer set retrieval from configurable element |
| 164 | CSyncerSet* getSyncerSet(const CConfigurableElement* pConfigurableElement) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 165 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 166 | // Configuration retrieval |
| 167 | CDomainConfiguration* findConfiguration(const string& strConfiguration, string& strError); |
| 168 | const CDomainConfiguration* findConfiguration(const string& strConfiguration, string& strError) const; |
| 169 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 170 | // Configurable elements |
| 171 | list<CConfigurableElement*> _configurableElementList; |
| 172 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 173 | // Associated syncer sets |
| 174 | map<const CConfigurableElement*, CSyncerSet*> _configurableElementToSyncerSetMap; |
| 175 | |
| 176 | // Sequence awareness |
| 177 | bool _bSequenceAware; |
| 178 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 179 | // Syncer set used to ensure propoer synchronization of restored configurable elements |
| 180 | CSyncerSet _syncerSet; |
| 181 | |
| 182 | // Last applied configuration |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 183 | mutable const CDomainConfiguration* _pLastAppliedConfiguration; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 184 | }; |
| 185 | |