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 | |
Kevin Rocard | 170f0a4 | 2012-06-18 13:56:05 +0200 | [diff] [blame^] | 160 | void CConfigurableDomains::deleteAllDomains() |
| 161 | { |
| 162 | log("Deleting all configurable domains"); |
| 163 | |
| 164 | //remove Children |
| 165 | clean(); |
| 166 | } |
| 167 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 168 | bool CConfigurableDomains::renameDomain(const string& strName, const string& strNewName, string& strError) |
| 169 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 170 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 171 | |
| 172 | if (!pConfigurableDomain) { |
| 173 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 174 | return false; |
| 175 | } |
| 176 | |
| 177 | log("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str()); |
| 178 | |
| 179 | // Rename |
| 180 | return pConfigurableDomain->rename(strNewName, strError); |
| 181 | } |
| 182 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 183 | bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bSequenceAware, string& strError) |
| 184 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 185 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 186 | |
| 187 | if (!pConfigurableDomain) { |
| 188 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 189 | return false; |
| 190 | } |
| 191 | |
| 192 | pConfigurableDomain->setSequenceAwareness(bSequenceAware); |
| 193 | |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& bSequenceAware, string& strError) const |
| 198 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 199 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 200 | |
| 201 | if (!pConfigurableDomain) { |
| 202 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | |
| 206 | bSequenceAware = pConfigurableDomain->getSequenceAwareness(); |
| 207 | |
| 208 | return true; |
| 209 | } |
| 210 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 211 | /// Configurations |
| 212 | bool CConfigurableDomains::listConfigurations(const string& strDomain, string& strResult) const |
| 213 | { |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 214 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 215 | |
| 216 | if (!pConfigurableDomain) { |
| 217 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 218 | return false; |
| 219 | } |
| 220 | // delegate |
| 221 | pConfigurableDomain->listChildren(strResult); |
| 222 | |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | bool CConfigurableDomains::createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 227 | { |
| 228 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 229 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 230 | |
| 231 | if (!pConfigurableDomain) { |
| 232 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 233 | return false; |
| 234 | } |
| 235 | // Delegate |
| 236 | return pConfigurableDomain->createConfiguration(strConfiguration, pMainBlackboard, strError); |
| 237 | } |
| 238 | |
| 239 | bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 240 | { |
| 241 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 242 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 243 | |
| 244 | if (!pConfigurableDomain) { |
| 245 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 246 | return false; |
| 247 | } |
| 248 | // Delegate |
| 249 | return pConfigurableDomain->deleteConfiguration(strConfiguration, strError); |
| 250 | } |
| 251 | |
| 252 | bool CConfigurableDomains::renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError) |
| 253 | { |
| 254 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 255 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 256 | |
| 257 | if (!pConfigurableDomain) { |
| 258 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 259 | return false; |
| 260 | } |
| 261 | // Delegate |
| 262 | return pConfigurableDomain->renameConfiguration(strConfigurationName, strNewConfigurationName, strError); |
| 263 | } |
| 264 | |
| 265 | bool CConfigurableDomains::listDomainElements(const string& strDomain, string& strResult) const |
| 266 | { |
| 267 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 268 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 269 | |
| 270 | if (!pConfigurableDomain) { |
| 271 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 272 | return false; |
| 273 | } |
| 274 | // Delegate |
| 275 | pConfigurableDomain->listAssociatedToElements(strResult); |
| 276 | |
| 277 | return true; |
| 278 | } |
| 279 | |
| 280 | bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) |
| 281 | { |
| 282 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 283 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 284 | |
| 285 | if (!pConfigurableDomain) { |
| 286 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 287 | return false; |
| 288 | } |
| 289 | // Delegate |
| 290 | pConfigurableDomain->split(pConfigurableElement, strError); |
| 291 | |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | void CConfigurableDomains::listAssociatedElements(string& strResult) const |
| 296 | { |
| 297 | strResult = "\n"; |
| 298 | |
| 299 | set<const CConfigurableElement*> configurableElementSet; |
| 300 | |
| 301 | // Get all owned configurable elements |
| 302 | gatherAllOwnedConfigurableElements(configurableElementSet); |
| 303 | |
| 304 | // Fill result |
| 305 | set<const CConfigurableElement*>::const_iterator it; |
| 306 | |
| 307 | for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) { |
| 308 | |
| 309 | const CConfigurableElement* pConfigurableElement = *it; |
| 310 | |
| 311 | string strAssociatedDomainList; |
| 312 | |
| 313 | pConfigurableElement->listAssociatedDomains(strAssociatedDomainList, false); |
| 314 | |
| 315 | strResult += pConfigurableElement->getPath() + " [" + strAssociatedDomainList + "]\n"; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void CConfigurableDomains::listConflictingElements(string& strResult) const |
| 320 | { |
| 321 | strResult = "\n"; |
| 322 | |
| 323 | set<const CConfigurableElement*> configurableElementSet; |
| 324 | |
| 325 | // Get all owned configurable elements |
| 326 | gatherAllOwnedConfigurableElements(configurableElementSet); |
| 327 | |
| 328 | // Fill result |
| 329 | set<const CConfigurableElement*>::const_iterator it; |
| 330 | |
| 331 | for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) { |
| 332 | |
| 333 | const CConfigurableElement* pConfigurableElement = *it; |
| 334 | |
| 335 | if (pConfigurableElement->getBelongingDomainCount() > 1) { |
| 336 | |
| 337 | string strBelongingDomainList; |
| 338 | |
| 339 | pConfigurableElement->listBelongingDomains(strBelongingDomainList, false); |
| 340 | |
| 341 | strResult += pConfigurableElement->getPath() + " contained in multiple domains: " + strBelongingDomainList + "\n"; |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 346 | void CConfigurableDomains::listDomains(string& strResult) const |
| 347 | { |
| 348 | strResult = "\n"; |
| 349 | |
| 350 | // List domains |
| 351 | uint32_t uiChild; |
| 352 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 353 | |
| 354 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 355 | |
| 356 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 357 | |
| 358 | // Name |
| 359 | strResult += pChildConfigurableDomain->getName(); |
| 360 | |
| 361 | // Sequence awareness |
| 362 | if (pChildConfigurableDomain->getSequenceAwareness()) { |
| 363 | |
Patrick Benavoli | 9bed7ce | 2011-11-20 20:04:35 +0100 | [diff] [blame] | 364 | strResult += " [sequence aware]"; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 365 | } |
Patrick Benavoli | 9bed7ce | 2011-11-20 20:04:35 +0100 | [diff] [blame] | 366 | strResult += "\n"; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 370 | // Gather configurable elements owned by any domain |
| 371 | void CConfigurableDomains::gatherAllOwnedConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const |
| 372 | { |
| 373 | // Delegate to domains |
| 374 | uint32_t uiChild; |
| 375 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 376 | |
| 377 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 378 | |
| 379 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 380 | |
| 381 | pChildConfigurableDomain->gatherConfigurableElements(configurableElementSet); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // Config restore |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 386 | 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] | 387 | { |
| 388 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 389 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 390 | |
| 391 | if (!pConfigurableDomain) { |
| 392 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 393 | return false; |
| 394 | } |
| 395 | // Delegate |
| 396 | return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, strError); |
| 397 | } |
| 398 | |
| 399 | // Config save |
| 400 | bool CConfigurableDomains::saveConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 401 | { |
| 402 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 403 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 404 | |
| 405 | if (!pConfigurableDomain) { |
| 406 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 407 | return false; |
| 408 | } |
| 409 | // Delegate |
| 410 | return pConfigurableDomain->saveConfiguration(strConfiguration, pMainBlackboard, strError); |
| 411 | } |
| 412 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 413 | bool CConfigurableDomains::setElementSequence(const string& strDomain, const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError) |
| 414 | { |
| 415 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 416 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 417 | |
| 418 | if (!pConfigurableDomain) { |
| 419 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 420 | return false; |
| 421 | } |
| 422 | |
| 423 | // Delegate to domain |
| 424 | return pConfigurableDomain->setElementSequence(strConfiguration, astrNewElementSequence, strError); |
| 425 | } |
| 426 | |
| 427 | bool CConfigurableDomains::getElementSequence(const string& strDomain, const string& strConfiguration, string& strResult) const |
| 428 | { |
| 429 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 430 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 431 | |
| 432 | if (!pConfigurableDomain) { |
| 433 | |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 434 | return false; |
| 435 | } |
| 436 | // Delegate to domain |
| 437 | return pConfigurableDomain->getElementSequence(strConfiguration, strResult); |
| 438 | } |
| 439 | |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 440 | bool CConfigurableDomains::setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) |
| 441 | { |
| 442 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| 443 | |
| 444 | if (!pConfigurableDomain) { |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | // Delegate to domain |
| 450 | return pConfigurableDomain->setApplicationRule(strConfiguration, strApplicationRule, pSelectionCriteriaDefinition, strError); |
| 451 | } |
| 452 | |
| 453 | bool CConfigurableDomains::clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError) |
| 454 | { |
| 455 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
| 456 | |
| 457 | if (!pConfigurableDomain) { |
| 458 | |
| 459 | return false; |
| 460 | } |
| 461 | |
| 462 | // Delegate to domain |
| 463 | return pConfigurableDomain->clearApplicationRule(strConfiguration, strError); |
| 464 | } |
| 465 | |
| 466 | bool CConfigurableDomains::getApplicationRule(const string& strDomain, const string& strConfiguration, string& strResult) const |
| 467 | { |
| 468 | const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); |
| 469 | |
| 470 | if (!pConfigurableDomain) { |
| 471 | |
| 472 | return false; |
| 473 | } |
| 474 | |
| 475 | // Delegate to domain |
| 476 | return pConfigurableDomain->getApplicationRule(strConfiguration, strResult); |
| 477 | } |
| 478 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 479 | // Last applied configurations |
| 480 | void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) const |
| 481 | { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 482 | // Browse domains |
| 483 | uint32_t uiChild; |
| 484 | uint32_t uiNbConfigurableDomains = getNbChildren(); |
| 485 | |
| 486 | for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) { |
| 487 | |
| 488 | const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild)); |
| 489 | |
| 490 | strResult += pChildConfigurableDomain->getName() + ": " + pChildConfigurableDomain->getLastAppliedConfigurationName() + "\n"; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | // Configurable element - domain association |
| 495 | bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) |
| 496 | { |
| 497 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 498 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 499 | |
| 500 | if (!pConfigurableDomain) { |
| 501 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 502 | return false; |
| 503 | } |
| 504 | // Delegate |
| 505 | return pConfigurableDomain->addConfigurableElement(pConfigurableElement, pMainBlackboard, strError); |
| 506 | } |
| 507 | |
| 508 | bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) |
| 509 | { |
| 510 | // Find domain |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 511 | CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 512 | |
| 513 | if (!pConfigurableDomain) { |
| 514 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 515 | return false; |
| 516 | } |
| 517 | // Delegate |
| 518 | return pConfigurableDomain->removeConfigurableElement(pConfigurableElement, strError); |
| 519 | } |
| 520 | |
| 521 | // Binary settings load/store |
| 522 | bool CConfigurableDomains::serializeSettings(const string& strBinarySettingsFilePath, bool bOut, uint8_t uiStructureChecksum, string& strError) |
| 523 | { |
| 524 | // Instantiate byte stream |
| 525 | CBinaryStream binarySettingsStream(strBinarySettingsFilePath, bOut, getDataSize(), uiStructureChecksum); |
| 526 | |
| 527 | // Open file |
| 528 | if (!binarySettingsStream.open(strError)) { |
| 529 | |
| 530 | strError = "Unable to open binary settings file " + strBinarySettingsFilePath + ": " + strError; |
| 531 | |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | // Serialize |
| 536 | binarySerialize(binarySettingsStream); |
| 537 | |
| 538 | // Close stream |
| 539 | binarySettingsStream.close(); |
| 540 | |
| 541 | return true; |
| 542 | } |
Patrick Benavoli | 0bd5054 | 2011-11-29 11:10:27 +0100 | [diff] [blame] | 543 | |
| 544 | // Domain retrieval |
| 545 | CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) |
| 546 | { |
| 547 | // Find domain |
| 548 | CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); |
| 549 | |
| 550 | if (!pConfigurableDomain) { |
| 551 | |
| 552 | strError = "Configurable domain " + strDomain + " not found"; |
| 553 | |
| 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | return pConfigurableDomain; |
| 558 | } |
| 559 | |
| 560 | const CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) const |
| 561 | { |
| 562 | // Find domain |
| 563 | const CConfigurableDomain* pConfigurableDomain = static_cast<const 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 | } |