blob: 48975d6b5c1d665ffb44c70ce7e36abdcdd18e59 [file] [log] [blame]
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +01001/*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * Copyright (c) 2011-2014, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Patrick Benavoli68a91282011-08-31 11:23:23 +020029 */
Kevin Rocardace81f82012-12-11 16:19:17 +010030#include <cassert>
Patrick Benavoli68a91282011-08-31 11:23:23 +020031#include "ConfigurableDomains.h"
32#include "ConfigurableDomain.h"
33#include "ConfigurableElement.h"
34#include "BinaryStream.h"
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020035#include "AutoLog.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020036
37#define base CBinarySerializableElement
38
Patrick Benavoli95ac0342011-11-07 20:32:51 +010039CConfigurableDomains::CConfigurableDomains()
Patrick Benavoli68a91282011-08-31 11:23:23 +020040{
41}
42
43string CConfigurableDomains::getKind() const
44{
45 return "ConfigurableDomains";
46}
47
48bool CConfigurableDomains::childrenAreDynamic() const
49{
50 return true;
51}
52
53// Ensure validity on whole domains from main blackboard
54void 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
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010069void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020070{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020071 CAutoLog autoLog(this, "Applying configurations");
Patrick Benavoli68a91282011-08-31 11:23:23 +020072
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010073 /// Delegate to domains
Patrick Benavoli68a91282011-08-31 11:23:23 +020074
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010075 // Start with domains that can be synchronized all at once (with passed syncer set)
Patrick Benavoli68a91282011-08-31 11:23:23 +020076 uint32_t uiChild;
77 uint32_t uiNbConfigurableDomains = getNbChildren();
78
79 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
80
Patrick Benavoli63499d42011-10-24 18:50:03 +020081 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
Patrick Benavoli68a91282011-08-31 11:23:23 +020082
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010083 // Apply and collect syncers when relevant
84 pChildConfigurableDomain->apply(pParameterBlackboard, &syncerSet, bForce);
Patrick Benavoli68a91282011-08-31 11:23:23 +020085 }
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010086 // Synchronize those collected syncers
Kevin Rocardace81f82012-12-11 16:19:17 +010087 syncerSet.sync(*pParameterBlackboard, false, NULL);
Patrick Benavoli63499d42011-10-24 18:50:03 +020088
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010089 // Then deal with domains that need to synchronize along apply
Patrick Benavoli63499d42011-10-24 18:50:03 +020090 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
91
92 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
93
Guillaume Denneulinf2fd15a2012-12-20 17:53:29 +010094 // Apply and synchronize when relevant
95 pChildConfigurableDomain->apply(pParameterBlackboard, NULL, bForce);
Patrick Benavoli63499d42011-10-24 18:50:03 +020096 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020097}
98
99// From IXmlSource
100void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
101{
102 // Set attribute
103 xmlElement.setAttributeString("SystemClassName", getName());
104
105 base::toXml(xmlElement, serializingContext);
106}
107
108// Configuration/Domains handling
109/// Domains
110bool CConfigurableDomains::createDomain(const string& strName, string& strError)
111{
112 // Already exists?
113 if (findChild(strName)) {
114
115 strError = "Already existing configurable domain";
116
117 return false;
118 }
119
Kevin Rocardace81f82012-12-11 16:19:17 +0100120 log_info("Creating configurable domain \"%s\"", strName.c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121
122 // Creation/Hierarchy
123 addChild(new CConfigurableDomain(strName));
124
125 return true;
126}
127
128bool CConfigurableDomains::deleteDomain(const string& strName, string& strError)
129{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100130 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200131
132 if (!pConfigurableDomain) {
133
Patrick Benavoli68a91282011-08-31 11:23:23 +0200134 return false;
135 }
136
Kevin Rocardace81f82012-12-11 16:19:17 +0100137 log_info("Deleting configurable domain \"%s\"", strName.c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200138
139 // Hierarchy
140 removeChild(pConfigurableDomain);
141
142 // Destroy
143 delete pConfigurableDomain;
144
145 return true;
146}
147
Kevin Rocard170f0a42012-06-18 13:56:05 +0200148void CConfigurableDomains::deleteAllDomains()
149{
Kevin Rocardace81f82012-12-11 16:19:17 +0100150 log_info("Deleting all configurable domains");
Kevin Rocard170f0a42012-06-18 13:56:05 +0200151
152 //remove Children
153 clean();
154}
155
Patrick Benavoli68a91282011-08-31 11:23:23 +0200156bool CConfigurableDomains::renameDomain(const string& strName, const string& strNewName, string& strError)
157{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100158 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200159
160 if (!pConfigurableDomain) {
161
Patrick Benavoli68a91282011-08-31 11:23:23 +0200162 return false;
163 }
164
Kevin Rocardace81f82012-12-11 16:19:17 +0100165 log_info("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200166
167 // Rename
168 return pConfigurableDomain->rename(strNewName, strError);
169}
170
Patrick Benavoli63499d42011-10-24 18:50:03 +0200171bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bSequenceAware, string& strError)
172{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100173 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200174
175 if (!pConfigurableDomain) {
176
Patrick Benavoli63499d42011-10-24 18:50:03 +0200177 return false;
178 }
179
180 pConfigurableDomain->setSequenceAwareness(bSequenceAware);
181
182 return true;
183}
184
185bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& bSequenceAware, string& strError) const
186{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100187 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200188
189 if (!pConfigurableDomain) {
190
Patrick Benavoli63499d42011-10-24 18:50:03 +0200191 return false;
192 }
193
194 bSequenceAware = pConfigurableDomain->getSequenceAwareness();
195
196 return true;
197}
198
Patrick Benavoli68a91282011-08-31 11:23:23 +0200199/// Configurations
200bool CConfigurableDomains::listConfigurations(const string& strDomain, string& strResult) const
201{
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100202 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200203
204 if (!pConfigurableDomain) {
205
Patrick Benavoli68a91282011-08-31 11:23:23 +0200206 return false;
207 }
208 // delegate
209 pConfigurableDomain->listChildren(strResult);
210
211 return true;
212}
213
214bool CConfigurableDomains::createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError)
215{
216 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100217 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200218
219 if (!pConfigurableDomain) {
220
Patrick Benavoli68a91282011-08-31 11:23:23 +0200221 return false;
222 }
223 // Delegate
224 return pConfigurableDomain->createConfiguration(strConfiguration, pMainBlackboard, strError);
225}
226
227bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
228{
229 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100230 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200231
232 if (!pConfigurableDomain) {
233
Patrick Benavoli68a91282011-08-31 11:23:23 +0200234 return false;
235 }
236 // Delegate
237 return pConfigurableDomain->deleteConfiguration(strConfiguration, strError);
238}
239
240bool CConfigurableDomains::renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError)
241{
242 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100243 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200244
245 if (!pConfigurableDomain) {
246
Patrick Benavoli68a91282011-08-31 11:23:23 +0200247 return false;
248 }
249 // Delegate
250 return pConfigurableDomain->renameConfiguration(strConfigurationName, strNewConfigurationName, strError);
251}
252
253bool CConfigurableDomains::listDomainElements(const string& strDomain, string& strResult) const
254{
255 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100256 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200257
258 if (!pConfigurableDomain) {
259
Patrick Benavoli68a91282011-08-31 11:23:23 +0200260 return false;
261 }
262 // Delegate
263 pConfigurableDomain->listAssociatedToElements(strResult);
264
265 return true;
266}
267
268bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError)
269{
270 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100271 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200272
273 if (!pConfigurableDomain) {
274
Patrick Benavoli68a91282011-08-31 11:23:23 +0200275 return false;
276 }
277 // Delegate
278 pConfigurableDomain->split(pConfigurableElement, strError);
279
280 return true;
281}
282
283void CConfigurableDomains::listAssociatedElements(string& strResult) const
284{
285 strResult = "\n";
286
287 set<const CConfigurableElement*> configurableElementSet;
288
289 // Get all owned configurable elements
290 gatherAllOwnedConfigurableElements(configurableElementSet);
291
292 // Fill result
293 set<const CConfigurableElement*>::const_iterator it;
294
295 for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) {
296
297 const CConfigurableElement* pConfigurableElement = *it;
298
299 string strAssociatedDomainList;
300
301 pConfigurableElement->listAssociatedDomains(strAssociatedDomainList, false);
302
303 strResult += pConfigurableElement->getPath() + " [" + strAssociatedDomainList + "]\n";
304 }
305}
306
307void CConfigurableDomains::listConflictingElements(string& strResult) const
308{
309 strResult = "\n";
310
311 set<const CConfigurableElement*> configurableElementSet;
312
313 // Get all owned configurable elements
314 gatherAllOwnedConfigurableElements(configurableElementSet);
315
316 // Fill result
317 set<const CConfigurableElement*>::const_iterator it;
318
319 for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) {
320
321 const CConfigurableElement* pConfigurableElement = *it;
322
323 if (pConfigurableElement->getBelongingDomainCount() > 1) {
324
325 string strBelongingDomainList;
326
327 pConfigurableElement->listBelongingDomains(strBelongingDomainList, false);
328
329 strResult += pConfigurableElement->getPath() + " contained in multiple domains: " + strBelongingDomainList + "\n";
330 }
331 }
332}
333
Patrick Benavoli63499d42011-10-24 18:50:03 +0200334void CConfigurableDomains::listDomains(string& strResult) const
335{
336 strResult = "\n";
337
338 // List domains
339 uint32_t uiChild;
340 uint32_t uiNbConfigurableDomains = getNbChildren();
341
342 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
343
344 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
345
346 // Name
347 strResult += pChildConfigurableDomain->getName();
348
349 // Sequence awareness
350 if (pChildConfigurableDomain->getSequenceAwareness()) {
351
Patrick Benavoli9bed7ce2011-11-20 20:04:35 +0100352 strResult += " [sequence aware]";
Patrick Benavoli63499d42011-10-24 18:50:03 +0200353 }
Patrick Benavoli9bed7ce2011-11-20 20:04:35 +0100354 strResult += "\n";
Patrick Benavoli63499d42011-10-24 18:50:03 +0200355 }
356}
357
Patrick Benavoli68a91282011-08-31 11:23:23 +0200358// Gather configurable elements owned by any domain
359void CConfigurableDomains::gatherAllOwnedConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const
360{
361 // Delegate to domains
362 uint32_t uiChild;
363 uint32_t uiNbConfigurableDomains = getNbChildren();
364
365 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
366
367 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
368
369 pChildConfigurableDomain->gatherConfigurableElements(configurableElementSet);
370 }
371}
372
373// Config restore
Kevin Rocardace81f82012-12-11 16:19:17 +0100374bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, list<string>& lstrError) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200375{
Kevin Rocardace81f82012-12-11 16:19:17 +0100376 string strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200377 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100378 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200379
380 if (!pConfigurableDomain) {
381
Kevin Rocardace81f82012-12-11 16:19:17 +0100382 lstrError.push_back(strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200383 return false;
384 }
385 // Delegate
Kevin Rocardace81f82012-12-11 16:19:17 +0100386 return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, lstrError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200387}
388
389// Config save
390bool CConfigurableDomains::saveConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError)
391{
392 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100393 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200394
395 if (!pConfigurableDomain) {
396
Patrick Benavoli68a91282011-08-31 11:23:23 +0200397 return false;
398 }
399 // Delegate
400 return pConfigurableDomain->saveConfiguration(strConfiguration, pMainBlackboard, strError);
401}
402
Patrick Benavoli63499d42011-10-24 18:50:03 +0200403bool CConfigurableDomains::setElementSequence(const string& strDomain, const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError)
404{
405 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100406 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200407
408 if (!pConfigurableDomain) {
409
Patrick Benavoli63499d42011-10-24 18:50:03 +0200410 return false;
411 }
412
413 // Delegate to domain
414 return pConfigurableDomain->setElementSequence(strConfiguration, astrNewElementSequence, strError);
415}
416
417bool CConfigurableDomains::getElementSequence(const string& strDomain, const string& strConfiguration, string& strResult) const
418{
419 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100420 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult);
Patrick Benavoli63499d42011-10-24 18:50:03 +0200421
422 if (!pConfigurableDomain) {
423
Patrick Benavoli63499d42011-10-24 18:50:03 +0200424 return false;
425 }
426 // Delegate to domain
427 return pConfigurableDomain->getElementSequence(strConfiguration, strResult);
428}
429
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100430bool CConfigurableDomains::setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError)
431{
432 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
433
434 if (!pConfigurableDomain) {
435
436 return false;
437 }
438
439 // Delegate to domain
440 return pConfigurableDomain->setApplicationRule(strConfiguration, strApplicationRule, pSelectionCriteriaDefinition, strError);
441}
442
443bool CConfigurableDomains::clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError)
444{
445 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
446
447 if (!pConfigurableDomain) {
448
449 return false;
450 }
451
452 // Delegate to domain
453 return pConfigurableDomain->clearApplicationRule(strConfiguration, strError);
454}
455
456bool CConfigurableDomains::getApplicationRule(const string& strDomain, const string& strConfiguration, string& strResult) const
457{
458 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult);
459
460 if (!pConfigurableDomain) {
461
462 return false;
463 }
464
465 // Delegate to domain
466 return pConfigurableDomain->getApplicationRule(strConfiguration, strResult);
467}
468
Patrick Benavoli68a91282011-08-31 11:23:23 +0200469// Last applied configurations
470void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) const
471{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200472 // Browse domains
473 uint32_t uiChild;
474 uint32_t uiNbConfigurableDomains = getNbChildren();
475
476 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
477
478 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
479
Frédéric Boisnard8b243f52012-09-06 18:03:20 +0200480 strResult += pChildConfigurableDomain->getName() + ": " + pChildConfigurableDomain->getLastAppliedConfigurationName() + " [" + pChildConfigurableDomain->getPendingConfigurationName() + "]\n";
Patrick Benavoli68a91282011-08-31 11:23:23 +0200481 }
482}
483
484// Configurable element - domain association
485bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError)
486{
487 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100488 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200489
490 if (!pConfigurableDomain) {
491
Patrick Benavoli68a91282011-08-31 11:23:23 +0200492 return false;
493 }
494 // Delegate
495 return pConfigurableDomain->addConfigurableElement(pConfigurableElement, pMainBlackboard, strError);
496}
497
498bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError)
499{
500 // Find domain
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100501 CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200502
503 if (!pConfigurableDomain) {
504
Patrick Benavoli68a91282011-08-31 11:23:23 +0200505 return false;
506 }
507 // Delegate
508 return pConfigurableDomain->removeConfigurableElement(pConfigurableElement, strError);
509}
510
Frédéric Boisnarde42dacd2013-02-25 15:56:56 +0100511CParameterBlackboard* CConfigurableDomains::findConfigurationBlackboard(const string& strDomain,
512 const string& strConfiguration,
513 const CConfigurableElement* pConfigurableElement,
514 uint32_t& uiBaseOffset,
515 bool& bIsLastApplied,
516 string& strError) const
517{
518 log_info("Find configuration blackboard for Domain:%s, Configuration:%s, Element:%s",
519 strDomain.c_str(), strConfiguration.c_str(), pConfigurableElement->getPath().c_str());
520
521 // Find domain
522 const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError);
523
524 if (!pConfigurableDomain) {
525
526 return NULL;
527 }
528
529 // Check that element belongs to the domain
530 if (!pConfigurableElement->belongsTo(pConfigurableDomain)) {
531
532 strError = "Element \"" + pConfigurableElement->getPath() + "\" does not belong to domain \"" + strDomain + "\"";
533
534 return NULL;
535 }
536
537 // Find Configuration Blackboard and Base Offset
538 return pConfigurableDomain->findConfigurationBlackboard(strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
539}
540
Patrick Benavoli68a91282011-08-31 11:23:23 +0200541// Binary settings load/store
542bool CConfigurableDomains::serializeSettings(const string& strBinarySettingsFilePath, bool bOut, uint8_t uiStructureChecksum, string& strError)
543{
544 // Instantiate byte stream
545 CBinaryStream binarySettingsStream(strBinarySettingsFilePath, bOut, getDataSize(), uiStructureChecksum);
546
547 // Open file
548 if (!binarySettingsStream.open(strError)) {
549
550 strError = "Unable to open binary settings file " + strBinarySettingsFilePath + ": " + strError;
551
552 return false;
553 }
554
555 // Serialize
556 binarySerialize(binarySettingsStream);
557
558 // Close stream
559 binarySettingsStream.close();
560
561 return true;
562}
Patrick Benavoli0bd50542011-11-29 11:10:27 +0100563
564// Domain retrieval
565CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError)
566{
567 // Find domain
568 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
569
570 if (!pConfigurableDomain) {
571
572 strError = "Configurable domain " + strDomain + " not found";
573
574 return NULL;
575 }
576
577 return pConfigurableDomain;
578}
579
580const CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) const
581{
582 // Find domain
583 const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain));
584
585 if (!pConfigurableDomain) {
586
587 strError = "Configurable domain " + strDomain + " not found";
588
589 return NULL;
590 }
591
592 return pConfigurableDomain;
593}