blob: b58efb512dcafc305a07a5759352829ade6731f6 [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>
Patrick Benavoli68a91282011-08-31 11:23:23 +020037
38class CConfigurableElement;
39class CDomainConfiguration;
40class CParameterBlackboard;
Patrick Benavoli0bd50542011-11-29 11:10:27 +010041class CSelectionCriteriaDefinition;
Patrick Benavoli68a91282011-08-31 11:23:23 +020042
43class CConfigurableDomain : public CBinarySerializableElement
44{
45 typedef list<CConfigurableElement*>::const_iterator ConfigurableElementListIterator;
Patrick Benavoli63499d42011-10-24 18:50:03 +020046 typedef map<const CConfigurableElement*, CSyncerSet*>::const_iterator ConfigurableElementToSyncerSetMapIterator;
Patrick Benavoli68a91282011-08-31 11:23:23 +020047public:
48 CConfigurableDomain(const string& strName);
49 virtual ~CConfigurableDomain();
50
Patrick Benavoli63499d42011-10-24 18:50:03 +020051 // Sequence awareness
52 void setSequenceAwareness(bool bSequenceAware);
53 bool getSequenceAwareness() const;
54
Patrick Benavoli68a91282011-08-31 11:23:23 +020055 // 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 Rocardace81f82012-12-11 16:19:17 +010059 bool restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, list<string>& strError) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020060 bool saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError);
Patrick Benavoli0bd50542011-11-29 11:10:27 +010061 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 Benavoli68a91282011-08-31 11:23:23 +020066
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020067 // Last applied configuration name
Patrick Benavoli68a91282011-08-31 11:23:23 +020068 string getLastAppliedConfigurationName() const;
69
Frédéric Boisnard8b243f52012-09-06 18:03:20 +020070 // Pending configuration name
71 string getPendingConfigurationName() const;
72
Patrick Benavoli68a91282011-08-31 11:23:23 +020073 // 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 Boisnarde42dacd2013-02-25 15:56:56 +010081 // 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 Benavoli68a91282011-08-31 11:23:23 +020088 // 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 Denneulinf2fd15a2012-12-20 17:53:29 +010095 void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020096
97 // Return applicable configuration validity for given configurable element
98 bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const;
99
Patrick Benavoli68a91282011-08-31 11:23:23 +0200100 // 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 Boisnard8b243f52012-09-06 18:03:20 +0200108
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100109protected:
110 // Content dumping
111 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200112
Patrick Benavoli68a91282011-08-31 11:23:23 +0200113private:
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200114 // Get pending configuration
115 const CDomainConfiguration* getPendingConfiguration() const;
116
117 // Search for an applicable configuration
118 const CDomainConfiguration* findApplicableDomainConfiguration() const;
119
Patrick Benavoli68a91282011-08-31 11:23:23 +0200120 // 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 Benavoli68a91282011-08-31 11:23:23 +0200138
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 Boisnard9620e442012-05-30 16:15:02 +0200150 void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200151 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 Benavoli63499d42011-10-24 18:50:03 +0200156 bool parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200157
158 // XML composing
159 void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
Patrick Benavoli63499d42011-10-24 18:50:03 +0200160 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 Benavoli68a91282011-08-31 11:23:23 +0200165
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100166 // Configuration retrieval
167 CDomainConfiguration* findConfiguration(const string& strConfiguration, string& strError);
168 const CDomainConfiguration* findConfiguration(const string& strConfiguration, string& strError) const;
169
Patrick Benavoli68a91282011-08-31 11:23:23 +0200170 // Configurable elements
171 list<CConfigurableElement*> _configurableElementList;
172
Patrick Benavoli63499d42011-10-24 18:50:03 +0200173 // Associated syncer sets
174 map<const CConfigurableElement*, CSyncerSet*> _configurableElementToSyncerSetMap;
175
176 // Sequence awareness
177 bool _bSequenceAware;
178
Patrick Benavoli68a91282011-08-31 11:23:23 +0200179 // Syncer set used to ensure propoer synchronization of restored configurable elements
180 CSyncerSet _syncerSet;
181
182 // Last applied configuration
Patrick Benavoli63499d42011-10-24 18:50:03 +0200183 mutable const CDomainConfiguration* _pLastAppliedConfiguration;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200184};
185