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