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