| 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 | */ |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 30 | #include <cassert> |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 31 | #include "ConfigurableDomains.h" |
| 32 | #include "ConfigurableDomain.h" |
| 33 | #include "ConfigurableElement.h" |
| 34 | #include "BinaryStream.h" |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 35 | #include "AutoLog.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 36 | |
| 37 | #define base CBinarySerializableElement |
| 38 | |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 39 | using std::string; |
| 40 | |
| Patrick Benavoli | 95ac034 | 2011-11-07 20:32:51 +0100 | [diff] [blame] | 41 | CConfigurableDomains::CConfigurableDomains() |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
| 45 | string CConfigurableDomains::getKind() const |
| 46 | { |
| 47 | return "ConfigurableDomains"; |
| 48 | } |
| 49 | |
| 50 | bool CConfigurableDomains::childrenAreDynamic() const |
| 51 | { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | // Ensure validity on whole domains from main blackboard |
| 56 | void CConfigurableDomains::validate(const CParameterBlackboard* pMainBlackboard) |
| 57 | { |
| 58 | // Delegate to domains |
| 59 | uint32_t uiChild; |
| 60 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 61 | |
| 62 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 63 | |
| 64 | CConfigurableDomain* pChildConfigurableDomain = static_cast<CConfigurableDomain*>(getChild(uiChild)); |
| 65 | |
| 66 | pChildConfigurableDomain->validate(pMainBlackboard); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Configuration application if required |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 71 | void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 72 | { |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 73 | CAutoLog autoLog(this, "Applying configurations"); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 74 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 75 | /// Delegate to domains |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 76 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 77 | // Start with domains that can be synchronized all at once (with passed syncer set) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 78 | uint32_t uiChild; |
| 79 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 80 | |
| 81 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 82 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 83 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 84 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 85 | // Apply and collect syncers when relevant |
| 86 | pChildConfigurableDomain->apply(pParameterBlackboard, &syncerSet, bForce); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 87 | } |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 88 | // Synchronize those collected syncers |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 89 | syncerSet.sync(*pParameterBlackboard, false, NULL); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 90 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 91 | // Then deal with domains that need to synchronize along apply |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 92 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 93 | |
| 94 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 95 | |
| Guillaume Denneulin | f2fd15a | 2012-12-20 17:53:29 +0100 | [diff] [blame] | 96 | // Apply and synchronize when relevant |
| 97 | pChildConfigurableDomain->apply(pParameterBlackboard, NULL, bForce); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 98 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // From IXmlSource |
| 102 | void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const |
| 103 | { |
| 104 | // Set attribute |
| 105 | xmlElement.setAttributeString("SystemClassName", getName()); |
| 106 | |
| David Wagner | 8cb5d88 | 2014-12-09 15:26:06 +0100 | [diff] [blame] | 107 | base::childrenToXml(xmlElement, serializingContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | // Configuration/Domains handling |
| 111 | /// Domains |
| 112 | bool CConfigurableDomains::createDomain(const string& strName, string& strError) |
| 113 | { |
| 114 | // Already exists? |
| 115 | if (findChild(strName)) { |
| 116 | |
| 117 | strError = "Already existing configurable domain"; |
| 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 122 | log_info("Creating configurable domain \"%s\"", strName.c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 123 | |
| 124 | // Creation/Hierarchy |
| 125 | addChild(new CConfigurableDomain(strName)); |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) |
| 131 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 132 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 133 | |
| 134 | if (!pConfigurableDomain) { |
| 135 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 139 | log_info("Deleting configurable domain \"%s\"", strName.c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 140 | |
| 141 | // Hierarchy |
| 142 | removeChild(pConfigurableDomain); |
| 143 | |
| 144 | // Destroy |
| 145 | delete pConfigurableDomain; |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | |
| Kevin Rocard | 170f0a4 | 2012-06-18 13:56:05 +0200 | [diff] [blame] | 150 | void CConfigurableDomains::deleteAllDomains() |
| 151 | { |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 152 | log_info("Deleting all configurable domains"); |
| Kevin Rocard | 170f0a4 | 2012-06-18 13:56:05 +0200 | [diff] [blame] | 153 | |
| 154 | //remove Children |
| 155 | clean(); |
| 156 | } |
| 157 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 158 | bool CConfigurableDomains::renameDomain(const string& strName, const string& strNewName, string& strError) |
| 159 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 160 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 161 | |
| 162 | if (!pConfigurableDomain) { |
| 163 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 164 | return false; |
| 165 | } |
| 166 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 167 | log_info("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 168 | |
| 169 | // Rename |
| 170 | return pConfigurableDomain->rename(strNewName, strError); |
| 171 | } |
| 172 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 173 | bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bSequenceAware, string& strError) |
| 174 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 175 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 176 | |
| 177 | if (!pConfigurableDomain) { |
| 178 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 179 | return false; |
| 180 | } |
| 181 | |
| 182 | pConfigurableDomain->setSequenceAwareness(bSequenceAware); |
| 183 | |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& bSequenceAware, string& strError) const |
| 188 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 189 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 190 | |
| 191 | if (!pConfigurableDomain) { |
| 192 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 193 | return false; |
| 194 | } |
| 195 | |
| 196 | bSequenceAware = pConfigurableDomain->getSequenceAwareness(); |
| 197 | |
| 198 | return true; |
| 199 | } |
| 200 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 201 | /// Configurations |
| 202 | bool CConfigurableDomains::listConfigurations(const string& strDomain, string& strResult) const |
| 203 | { |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 204 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 205 | |
| 206 | if (!pConfigurableDomain) { |
| 207 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 208 | return false; |
| 209 | } |
| 210 | // delegate |
| 211 | pConfigurableDomain->listChildren(strResult); |
| 212 | |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | bool CConfigurableDomains::createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 217 | { |
| 218 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 219 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 220 | |
| 221 | if (!pConfigurableDomain) { |
| 222 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 223 | return false; |
| 224 | } |
| 225 | // Delegate |
| 226 | return pConfigurableDomain->createConfiguration(strConfiguration, pMainBlackboard, strError); |
| 227 | } |
| 228 | |
| 229 | bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 230 | { |
| 231 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 232 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 233 | |
| 234 | if (!pConfigurableDomain) { |
| 235 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | // Delegate |
| 239 | return pConfigurableDomain->deleteConfiguration(strConfiguration, strError); |
| 240 | } |
| 241 | |
| 242 | bool CConfigurableDomains::renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError) |
| 243 | { |
| 244 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 245 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 246 | |
| 247 | if (!pConfigurableDomain) { |
| 248 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 249 | return false; |
| 250 | } |
| 251 | // Delegate |
| 252 | return pConfigurableDomain->renameConfiguration(strConfigurationName, strNewConfigurationName, strError); |
| 253 | } |
| 254 | |
| 255 | bool CConfigurableDomains::listDomainElements(const string& strDomain, string& strResult) const |
| 256 | { |
| 257 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 258 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 259 | |
| 260 | if (!pConfigurableDomain) { |
| 261 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 262 | return false; |
| 263 | } |
| 264 | // Delegate |
| 265 | pConfigurableDomain->listAssociatedToElements(strResult); |
| 266 | |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) |
| 271 | { |
| 272 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 273 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 274 | |
| 275 | if (!pConfigurableDomain) { |
| 276 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | // Delegate |
| 280 | pConfigurableDomain->split(pConfigurableElement, strError); |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | void CConfigurableDomains::listAssociatedElements(string& strResult) const |
| 286 | { |
| 287 | strResult = "\n"; |
| 288 | |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 289 | std::set<const CConfigurableElement*> configurableElementSet; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 290 | |
| 291 | // Get all owned configurable elements |
| 292 | gatherAllOwnedConfigurableElements(configurableElementSet); |
| 293 | |
| 294 | // Fill result |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 295 | std::set<const CConfigurableElement*>::const_iterator it; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 296 | |
| 297 | for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) { |
| 298 | |
| 299 | const CConfigurableElement* pConfigurableElement = *it; |
| 300 | |
| 301 | string strAssociatedDomainList; |
| 302 | |
| 303 | pConfigurableElement->listAssociatedDomains(strAssociatedDomainList, false); |
| 304 | |
| 305 | strResult += pConfigurableElement->getPath() + " [" + strAssociatedDomainList + "]\n"; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void CConfigurableDomains::listConflictingElements(string& strResult) const |
| 310 | { |
| 311 | strResult = "\n"; |
| 312 | |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 313 | std::set<const CConfigurableElement*> configurableElementSet; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 314 | |
| 315 | // Get all owned configurable elements |
| 316 | gatherAllOwnedConfigurableElements(configurableElementSet); |
| 317 | |
| 318 | // Fill result |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 319 | std::set<const CConfigurableElement*>::const_iterator it; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 320 | |
| 321 | for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) { |
| 322 | |
| 323 | const CConfigurableElement* pConfigurableElement = *it; |
| 324 | |
| 325 | if (pConfigurableElement->getBelongingDomainCount() > 1) { |
| 326 | |
| 327 | string strBelongingDomainList; |
| 328 | |
| 329 | pConfigurableElement->listBelongingDomains(strBelongingDomainList, false); |
| 330 | |
| 331 | strResult += pConfigurableElement->getPath() + " contained in multiple domains: " + strBelongingDomainList + "\n"; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 336 | void CConfigurableDomains::listDomains(string& strResult) const |
| 337 | { |
| 338 | strResult = "\n"; |
| 339 | |
| 340 | // List domains |
| 341 | uint32_t uiChild; |
| 342 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 343 | |
| 344 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 345 | |
| 346 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 347 | |
| 348 | // Name |
| 349 | strResult += pChildConfigurableDomain->getName(); |
| 350 | |
| 351 | // Sequence awareness |
| 352 | if (pChildConfigurableDomain->getSequenceAwareness()) { |
| 353 | |
| Patrick Benavoli | 9bed7ce | 2011-11-20 20:04:35 +0100 | [diff] [blame] | 354 | strResult += " [sequence aware]"; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 355 | } |
| Patrick Benavoli | 9bed7ce | 2011-11-20 20:04:35 +0100 | [diff] [blame] | 356 | strResult += "\n"; |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 360 | // Gather configurable elements owned by any domain |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 361 | void CConfigurableDomains::gatherAllOwnedConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 362 | { |
| 363 | // Delegate to domains |
| 364 | uint32_t uiChild; |
| 365 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 366 | |
| 367 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 368 | |
| 369 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 370 | |
| 371 | pChildConfigurableDomain->gatherConfigurableElements(configurableElementSet); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // Config restore |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 376 | bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list<string>& lstrError) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 377 | { |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 378 | string strError; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 379 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 380 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 381 | |
| 382 | if (!pConfigurableDomain) { |
| 383 | |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 384 | lstrError.push_back(strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 385 | return false; |
| 386 | } |
| 387 | // Delegate |
| Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 388 | return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, lstrError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | // Config save |
| 392 | bool CConfigurableDomains::saveConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 393 | { |
| 394 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 395 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 396 | |
| 397 | if (!pConfigurableDomain) { |
| 398 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 399 | return false; |
| 400 | } |
| 401 | // Delegate |
| 402 | return pConfigurableDomain->saveConfiguration(strConfiguration, pMainBlackboard, strError); |
| 403 | } |
| 404 | |
| Sebastien Gonzalve | d952649 | 2014-02-20 22:28:03 +0100 | [diff] [blame] | 405 | bool CConfigurableDomains::setElementSequence(const string& strDomain, const string& strConfiguration, const std::vector<string>& astrNewElementSequence, string& strError) |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 406 | { |
| 407 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 408 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 409 | |
| 410 | if (!pConfigurableDomain) { |
| 411 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 412 | return false; |
| 413 | } |
| 414 | |
| 415 | // Delegate to domain |
| 416 | return pConfigurableDomain->setElementSequence(strConfiguration, astrNewElementSequence, strError); |
| 417 | } |
| 418 | |
| 419 | bool CConfigurableDomains::getElementSequence(const string& strDomain, const string& strConfiguration, string& strResult) const |
| 420 | { |
| 421 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 422 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 423 | |
| 424 | if (!pConfigurableDomain) { |
| 425 | |
| Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | // Delegate to domain |
| 429 | return pConfigurableDomain->getElementSequence(strConfiguration, strResult); |
| 430 | } |
| 431 | |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 432 | bool CConfigurableDomains::setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) |
| 433 | { |
| 434 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| 435 | |
| 436 | if (!pConfigurableDomain) { |
| 437 | |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | // Delegate to domain |
| 442 | return pConfigurableDomain->setApplicationRule(strConfiguration, strApplicationRule, pSelectionCriteriaDefinition, strError); |
| 443 | } |
| 444 | |
| 445 | bool CConfigurableDomains::clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError) |
| 446 | { |
| 447 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| 448 | |
| 449 | if (!pConfigurableDomain) { |
| 450 | |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | // Delegate to domain |
| 455 | return pConfigurableDomain->clearApplicationRule(strConfiguration, strError); |
| 456 | } |
| 457 | |
| 458 | bool CConfigurableDomains::getApplicationRule(const string& strDomain, const string& strConfiguration, string& strResult) const |
| 459 | { |
| 460 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
| 461 | |
| 462 | if (!pConfigurableDomain) { |
| 463 | |
| 464 | return false; |
| 465 | } |
| 466 | |
| 467 | // Delegate to domain |
| 468 | return pConfigurableDomain->getApplicationRule(strConfiguration, strResult); |
| 469 | } |
| 470 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 471 | // Last applied configurations |
| 472 | void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) const |
| 473 | { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 474 | // Browse domains |
| 475 | uint32_t uiChild; |
| 476 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 477 | |
| 478 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 479 | |
| 480 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 481 | |
| Frédéric Boisnard | 8b243f5 | 2012-09-06 18:03:20 +0200 | [diff] [blame] | 482 | strResult += pChildConfigurableDomain->getName() + ": " + pChildConfigurableDomain->getLastAppliedConfigurationName() + " [" + pChildConfigurableDomain->getPendingConfigurationName() + "]\n"; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | // Configurable element - domain association |
| 487 | bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 488 | { |
| 489 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 490 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 491 | |
| 492 | if (!pConfigurableDomain) { |
| 493 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 494 | return false; |
| 495 | } |
| 496 | // Delegate |
| 497 | return pConfigurableDomain->addConfigurableElement(pConfigurableElement, pMainBlackboard, strError); |
| 498 | } |
| 499 | |
| 500 | bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) |
| 501 | { |
| 502 | // Find domain |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 503 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 504 | |
| 505 | if (!pConfigurableDomain) { |
| 506 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 507 | return false; |
| 508 | } |
| 509 | // Delegate |
| 510 | return pConfigurableDomain->removeConfigurableElement(pConfigurableElement, strError); |
| 511 | } |
| 512 | |
| Frédéric Boisnard | e42dacd | 2013-02-25 15:56:56 +0100 | [diff] [blame] | 513 | CParameterBlackboard* CConfigurableDomains::findConfigurationBlackboard(const string& strDomain, |
| 514 | const string& strConfiguration, |
| 515 | const CConfigurableElement* pConfigurableElement, |
| 516 | uint32_t& uiBaseOffset, |
| 517 | bool& bIsLastApplied, |
| 518 | string& strError) const |
| 519 | { |
| 520 | log_info("Find configuration blackboard for Domain:%s, Configuration:%s, Element:%s", |
| 521 | strDomain.c_str(), strConfiguration.c_str(), pConfigurableElement->getPath().c_str()); |
| 522 | |
| 523 | // Find domain |
| 524 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| 525 | |
| 526 | if (!pConfigurableDomain) { |
| 527 | |
| 528 | return NULL; |
| 529 | } |
| 530 | |
| 531 | // Check that element belongs to the domain |
| 532 | if (!pConfigurableElement->belongsTo(pConfigurableDomain)) { |
| 533 | |
| 534 | strError = "Element \"" + pConfigurableElement->getPath() + "\" does not belong to domain \"" + strDomain + "\""; |
| 535 | |
| 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | // Find Configuration Blackboard and Base Offset |
| 540 | return pConfigurableDomain->findConfigurationBlackboard(strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError); |
| 541 | } |
| 542 | |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 543 | // Binary settings load/store |
| 544 | bool CConfigurableDomains::serializeSettings(const string& strBinarySettingsFilePath, bool bOut, uint8_t uiStructureChecksum, string& strError) |
| 545 | { |
| 546 | // Instantiate byte stream |
| 547 | CBinaryStream binarySettingsStream(strBinarySettingsFilePath, bOut, getDataSize(), uiStructureChecksum); |
| 548 | |
| 549 | // Open file |
| 550 | if (!binarySettingsStream.open(strError)) { |
| 551 | |
| 552 | strError = "Unable to open binary settings file " + strBinarySettingsFilePath + ": " + strError; |
| 553 | |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | // Serialize |
| 558 | binarySerialize(binarySettingsStream); |
| 559 | |
| 560 | // Close stream |
| 561 | binarySettingsStream.close(); |
| 562 | |
| 563 | return true; |
| 564 | } |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 565 | |
| 566 | // Domain retrieval |
| 567 | CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) |
| 568 | { |
| David Wagner | 12de2f2 | 2014-12-04 11:40:00 +0100 | [diff] [blame^] | 569 | // Call the const equivalent |
| 570 | return const_cast<CConfigurableDomain*>( |
| 571 | static_cast<const CConfigurableDomains*>(this)->findConfigurableDomain(strDomain, strError) |
| 572 | ); |
| Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | const CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) const |
| 576 | { |
| 577 | // Find domain |
| 578 | const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain)); |
| 579 | |
| 580 | if (!pConfigurableDomain) { |
| 581 | |
| 582 | strError = "Configurable domain " + strDomain + " not found"; |
| 583 | |
| 584 | return NULL; |
| 585 | } |
| 586 | |
| 587 | return pConfigurableDomain; |
| 588 | } |