Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1 | /* <auto_header> |
| 2 | * <FILENAME> |
| 3 | * |
| 4 | * INTEL CONFIDENTIAL |
| 5 | * Copyright © 2011 Intel |
| 6 | * Corporation All Rights Reserved. |
| 7 | * |
| 8 | * The source code contained or described herein and all documents related to |
| 9 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 10 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 11 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 12 | * and confidential information of Intel or its suppliers and licensors. The |
| 13 | * Material is protected by worldwide copyright and trade secret laws and |
| 14 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 15 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 16 | * disclosed in any way without Intel’s prior express written permission. |
| 17 | * |
| 18 | * No license under any patent, copyright, trade secret or other intellectual |
| 19 | * property right is granted to or conferred upon you by disclosure or delivery |
| 20 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 21 | * otherwise. Any license under such intellectual property rights must be |
| 22 | * express and approved by Intel in writing. |
| 23 | * |
| 24 | * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) |
| 25 | * CREATED: 2011-06-01 |
| 26 | * UPDATED: 2011-07-27 |
| 27 | * |
| 28 | * |
| 29 | * </auto_header> |
| 30 | */ |
| 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 | |
Patrick Benavoli | 95ac034 | 2011-11-07 20:32:51 +0100 | [diff] [blame] | 39 | CConfigurableDomains::CConfigurableDomains() |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | string CConfigurableDomains::getKind() const |
| 44 | { |
| 45 | return "ConfigurableDomains"; |
| 46 | } |
| 47 | |
| 48 | bool CConfigurableDomains::childrenAreDynamic() const |
| 49 | { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | // Ensure validity on whole domains from main blackboard |
| 54 | void CConfigurableDomains::validate(const CParameterBlackboard* pMainBlackboard) |
| 55 | { |
| 56 | // Delegate to domains |
| 57 | uint32_t uiChild; |
| 58 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 59 | |
| 60 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 61 | |
| 62 | CConfigurableDomain* pChildConfigurableDomain = static_cast<CConfigurableDomain*>(getChild(uiChild)); |
| 63 | |
| 64 | pChildConfigurableDomain->validate(pMainBlackboard); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Configuration application if required |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 69 | bool CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, bool bForce, string& strError) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 70 | { |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 71 | CAutoLog autoLog(this, "Applying configurations"); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 72 | |
| 73 | // Syncer set |
| 74 | CSyncerSet syncerSet; |
| 75 | |
| 76 | // Delegate to domains |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 77 | |
| 78 | // Start with sequence unaware domains |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 79 | uint32_t uiChild; |
| 80 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 81 | |
| 82 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 83 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 84 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 85 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 86 | if (!pChildConfigurableDomain->getSequenceAwareness() && !pChildConfigurableDomain->apply(pParameterBlackboard, syncerSet, bForce, strError)) { |
| 87 | |
| 88 | return false; |
| 89 | } |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 90 | } |
| 91 | // Synchronize |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 92 | if (!syncerSet.sync(*pParameterBlackboard, false, strError)) { |
| 93 | |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | // Then deal with sequence aware domains |
| 98 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 99 | |
| 100 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 101 | |
| 102 | if (pChildConfigurableDomain->getSequenceAwareness() && !pChildConfigurableDomain->apply(pParameterBlackboard, syncerSet, bForce, strError)) { |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return true; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // From IXmlSource |
| 112 | void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const |
| 113 | { |
| 114 | // Set attribute |
| 115 | xmlElement.setAttributeString("SystemClassName", getName()); |
| 116 | |
| 117 | base::toXml(xmlElement, serializingContext); |
| 118 | } |
| 119 | |
| 120 | // Configuration/Domains handling |
| 121 | /// Domains |
| 122 | bool CConfigurableDomains::createDomain(const string& strName, string& strError) |
| 123 | { |
| 124 | // Already exists? |
| 125 | if (findChild(strName)) { |
| 126 | |
| 127 | strError = "Already existing configurable domain"; |
| 128 | |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | log("Creating configurable domain \"%s\"", strName.c_str()); |
| 133 | |
| 134 | // Creation/Hierarchy |
| 135 | addChild(new CConfigurableDomain(strName)); |
| 136 | |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) |
| 141 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 142 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 143 | |
| 144 | if (!pConfigurableDomain) { |
| 145 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 146 | return false; |
| 147 | } |
| 148 | |
| 149 | log("Deleting configurable domain \"%s\"", strName.c_str()); |
| 150 | |
| 151 | // Hierarchy |
| 152 | removeChild(pConfigurableDomain); |
| 153 | |
| 154 | // Destroy |
| 155 | delete pConfigurableDomain; |
| 156 | |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | bool CConfigurableDomains::renameDomain(const string& strName, const string& strNewName, string& strError) |
| 161 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 162 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 163 | |
| 164 | if (!pConfigurableDomain) { |
| 165 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 166 | return false; |
| 167 | } |
| 168 | |
| 169 | log("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str()); |
| 170 | |
| 171 | // Rename |
| 172 | return pConfigurableDomain->rename(strNewName, strError); |
| 173 | } |
| 174 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 175 | bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bSequenceAware, string& strError) |
| 176 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 177 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 178 | |
| 179 | if (!pConfigurableDomain) { |
| 180 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 181 | return false; |
| 182 | } |
| 183 | |
| 184 | pConfigurableDomain->setSequenceAwareness(bSequenceAware); |
| 185 | |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& bSequenceAware, string& strError) const |
| 190 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 191 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 192 | |
| 193 | if (!pConfigurableDomain) { |
| 194 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | |
| 198 | bSequenceAware = pConfigurableDomain->getSequenceAwareness(); |
| 199 | |
| 200 | return true; |
| 201 | } |
| 202 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 203 | /// Configurations |
| 204 | bool CConfigurableDomains::listConfigurations(const string& strDomain, string& strResult) const |
| 205 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 206 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 207 | |
| 208 | if (!pConfigurableDomain) { |
| 209 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 210 | return false; |
| 211 | } |
| 212 | // delegate |
| 213 | pConfigurableDomain->listChildren(strResult); |
| 214 | |
| 215 | return true; |
| 216 | } |
| 217 | |
| 218 | bool CConfigurableDomains::createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 219 | { |
| 220 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 221 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 222 | |
| 223 | if (!pConfigurableDomain) { |
| 224 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 225 | return false; |
| 226 | } |
| 227 | // Delegate |
| 228 | return pConfigurableDomain->createConfiguration(strConfiguration, pMainBlackboard, strError); |
| 229 | } |
| 230 | |
| 231 | bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 232 | { |
| 233 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 234 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 235 | |
| 236 | if (!pConfigurableDomain) { |
| 237 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | // Delegate |
| 241 | return pConfigurableDomain->deleteConfiguration(strConfiguration, strError); |
| 242 | } |
| 243 | |
| 244 | bool CConfigurableDomains::renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError) |
| 245 | { |
| 246 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 247 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 248 | |
| 249 | if (!pConfigurableDomain) { |
| 250 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 251 | return false; |
| 252 | } |
| 253 | // Delegate |
| 254 | return pConfigurableDomain->renameConfiguration(strConfigurationName, strNewConfigurationName, strError); |
| 255 | } |
| 256 | |
| 257 | bool CConfigurableDomains::listDomainElements(const string& strDomain, string& strResult) const |
| 258 | { |
| 259 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 260 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 261 | |
| 262 | if (!pConfigurableDomain) { |
| 263 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | // Delegate |
| 267 | pConfigurableDomain->listAssociatedToElements(strResult); |
| 268 | |
| 269 | return true; |
| 270 | } |
| 271 | |
| 272 | bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) |
| 273 | { |
| 274 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 275 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 276 | |
| 277 | if (!pConfigurableDomain) { |
| 278 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 279 | return false; |
| 280 | } |
| 281 | // Delegate |
| 282 | pConfigurableDomain->split(pConfigurableElement, strError); |
| 283 | |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | void CConfigurableDomains::listAssociatedElements(string& strResult) const |
| 288 | { |
| 289 | strResult = "\n"; |
| 290 | |
| 291 | set<const CConfigurableElement*> configurableElementSet; |
| 292 | |
| 293 | // Get all owned configurable elements |
| 294 | gatherAllOwnedConfigurableElements(configurableElementSet); |
| 295 | |
| 296 | // Fill result |
| 297 | set<const CConfigurableElement*>::const_iterator it; |
| 298 | |
| 299 | for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) { |
| 300 | |
| 301 | const CConfigurableElement* pConfigurableElement = *it; |
| 302 | |
| 303 | string strAssociatedDomainList; |
| 304 | |
| 305 | pConfigurableElement->listAssociatedDomains(strAssociatedDomainList, false); |
| 306 | |
| 307 | strResult += pConfigurableElement->getPath() + " [" + strAssociatedDomainList + "]\n"; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | void CConfigurableDomains::listConflictingElements(string& strResult) const |
| 312 | { |
| 313 | strResult = "\n"; |
| 314 | |
| 315 | set<const CConfigurableElement*> configurableElementSet; |
| 316 | |
| 317 | // Get all owned configurable elements |
| 318 | gatherAllOwnedConfigurableElements(configurableElementSet); |
| 319 | |
| 320 | // Fill result |
| 321 | set<const CConfigurableElement*>::const_iterator it; |
| 322 | |
| 323 | for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) { |
| 324 | |
| 325 | const CConfigurableElement* pConfigurableElement = *it; |
| 326 | |
| 327 | if (pConfigurableElement->getBelongingDomainCount() > 1) { |
| 328 | |
| 329 | string strBelongingDomainList; |
| 330 | |
| 331 | pConfigurableElement->listBelongingDomains(strBelongingDomainList, false); |
| 332 | |
| 333 | strResult += pConfigurableElement->getPath() + " contained in multiple domains: " + strBelongingDomainList + "\n"; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 338 | void CConfigurableDomains::listDomains(string& strResult) const |
| 339 | { |
| 340 | strResult = "\n"; |
| 341 | |
| 342 | // List domains |
| 343 | uint32_t uiChild; |
| 344 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 345 | |
| 346 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 347 | |
| 348 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 349 | |
| 350 | // Name |
| 351 | strResult += pChildConfigurableDomain->getName(); |
| 352 | |
| 353 | // Sequence awareness |
| 354 | if (pChildConfigurableDomain->getSequenceAwareness()) { |
| 355 | |
Patrick Benavoli | 9bed7ce | 2011-11-20 20:04:35 +0100 | [diff] [blame] | 356 | strResult += " [sequence aware]"; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 357 | } |
Patrick Benavoli | 9bed7ce | 2011-11-20 20:04:35 +0100 | [diff] [blame] | 358 | strResult += "\n"; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 362 | // Gather configurable elements owned by any domain |
| 363 | void CConfigurableDomains::gatherAllOwnedConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const |
| 364 | { |
| 365 | // Delegate to domains |
| 366 | uint32_t uiChild; |
| 367 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 368 | |
| 369 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 370 | |
| 371 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 372 | |
| 373 | pChildConfigurableDomain->gatherConfigurableElements(configurableElementSet); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | // Config restore |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 378 | bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 379 | { |
| 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 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 385 | return false; |
| 386 | } |
| 387 | // Delegate |
| 388 | return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, strError); |
| 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 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 405 | bool CConfigurableDomains::setElementSequence(const string& strDomain, const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError) |
| 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 | |
| 482 | strResult += pChildConfigurableDomain->getName() + ": " + pChildConfigurableDomain->getLastAppliedConfigurationName() + "\n"; |
| 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 | |
| 513 | // Binary settings load/store |
| 514 | bool CConfigurableDomains::serializeSettings(const string& strBinarySettingsFilePath, bool bOut, uint8_t uiStructureChecksum, string& strError) |
| 515 | { |
| 516 | // Instantiate byte stream |
| 517 | CBinaryStream binarySettingsStream(strBinarySettingsFilePath, bOut, getDataSize(), uiStructureChecksum); |
| 518 | |
| 519 | // Open file |
| 520 | if (!binarySettingsStream.open(strError)) { |
| 521 | |
| 522 | strError = "Unable to open binary settings file " + strBinarySettingsFilePath + ": " + strError; |
| 523 | |
| 524 | return false; |
| 525 | } |
| 526 | |
| 527 | // Serialize |
| 528 | binarySerialize(binarySettingsStream); |
| 529 | |
| 530 | // Close stream |
| 531 | binarySettingsStream.close(); |
| 532 | |
| 533 | return true; |
| 534 | } |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame^] | 535 | |
| 536 | // Domain retrieval |
| 537 | CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) |
| 538 | { |
| 539 | // Find domain |
| 540 | CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); |
| 541 | |
| 542 | if (!pConfigurableDomain) { |
| 543 | |
| 544 | strError = "Configurable domain " + strDomain + " not found"; |
| 545 | |
| 546 | return NULL; |
| 547 | } |
| 548 | |
| 549 | return pConfigurableDomain; |
| 550 | } |
| 551 | |
| 552 | const CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) const |
| 553 | { |
| 554 | // Find domain |
| 555 | const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain)); |
| 556 | |
| 557 | if (!pConfigurableDomain) { |
| 558 | |
| 559 | strError = "Configurable domain " + strDomain + " not found"; |
| 560 | |
| 561 | return NULL; |
| 562 | } |
| 563 | |
| 564 | return pConfigurableDomain; |
| 565 | } |