blob: d021d8cd77e8fee769a2e6dc5a0633ef57f8ec6c [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <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 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
Patrick Benavoli63499d42011-10-24 18:50:03 +020069bool CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, bool bForce, string& strError) 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
73 // Syncer set
74 CSyncerSet syncerSet;
75
76 // Delegate to domains
Patrick Benavoli63499d42011-10-24 18:50:03 +020077
78 // Start with sequence unaware domains
Patrick Benavoli68a91282011-08-31 11:23:23 +020079 uint32_t uiChild;
80 uint32_t uiNbConfigurableDomains = getNbChildren();
81
82 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
83
Patrick Benavoli63499d42011-10-24 18:50:03 +020084 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
Patrick Benavoli68a91282011-08-31 11:23:23 +020085
Patrick Benavoli63499d42011-10-24 18:50:03 +020086 if (!pChildConfigurableDomain->getSequenceAwareness() && !pChildConfigurableDomain->apply(pParameterBlackboard, syncerSet, bForce, strError)) {
87
88 return false;
89 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020090 }
91 // Synchronize
Patrick Benavoli63499d42011-10-24 18:50:03 +020092 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 Benavoli68a91282011-08-31 11:23:23 +0200109}
110
111// From IXmlSource
112void 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
122bool 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
140bool CConfigurableDomains::deleteDomain(const string& strName, string& strError)
141{
142 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strName));
143
144 if (!pConfigurableDomain) {
145
146 strError = "Configurable domain not found";
147
148 return false;
149 }
150
151 // Check domain has no rule (prevent accidental loss of data)
152 if (pConfigurableDomain->hasRules()) {
153
154 strError = "Deletion of domain containing configurations with application rules is not supported to prevent any accitental loss of data.\nPlease consider a direct modification of the XML file.";
155
156 return false;
157 }
158
159 log("Deleting configurable domain \"%s\"", strName.c_str());
160
161 // Hierarchy
162 removeChild(pConfigurableDomain);
163
164 // Destroy
165 delete pConfigurableDomain;
166
167 return true;
168}
169
170bool CConfigurableDomains::renameDomain(const string& strName, const string& strNewName, string& strError)
171{
172 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strName));
173
174 if (!pConfigurableDomain) {
175
176 strError = "Configurable domain not found";
177
178 return false;
179 }
180
181 log("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str());
182
183 // Rename
184 return pConfigurableDomain->rename(strNewName, strError);
185}
186
Patrick Benavoli63499d42011-10-24 18:50:03 +0200187bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bSequenceAware, string& strError)
188{
189 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
190
191 if (!pConfigurableDomain) {
192
193 strError = "Configurable domain not found";
194
195 return false;
196 }
197
198 pConfigurableDomain->setSequenceAwareness(bSequenceAware);
199
200 return true;
201}
202
203bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& bSequenceAware, string& strError) const
204{
205 const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain));
206
207 if (!pConfigurableDomain) {
208
209 strError = "Configurable domain not found";
210
211 return false;
212 }
213
214 bSequenceAware = pConfigurableDomain->getSequenceAwareness();
215
216 return true;
217}
218
Patrick Benavoli68a91282011-08-31 11:23:23 +0200219/// Configurations
220bool CConfigurableDomains::listConfigurations(const string& strDomain, string& strResult) const
221{
222 const CElement* pConfigurableDomain = findChild(strDomain);
223
224 if (!pConfigurableDomain) {
225
226 strResult = "Configurable domain not found";
227
228 return false;
229 }
230 // delegate
231 pConfigurableDomain->listChildren(strResult);
232
233 return true;
234}
235
236bool CConfigurableDomains::createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError)
237{
238 // Find domain
239 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
240
241 if (!pConfigurableDomain) {
242
243 strError = "Configurable domain " + strDomain + " not found";
244
245 return false;
246 }
247 // Delegate
248 return pConfigurableDomain->createConfiguration(strConfiguration, pMainBlackboard, strError);
249}
250
251bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
252{
253 // Find domain
254 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
255
256 if (!pConfigurableDomain) {
257
258 strError = "Configurable domain " + strDomain + " not found";
259
260 return false;
261 }
262 // Delegate
263 return pConfigurableDomain->deleteConfiguration(strConfiguration, strError);
264}
265
266bool CConfigurableDomains::renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError)
267{
268 // Find domain
269 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
270
271 if (!pConfigurableDomain) {
272
273 strError = "Configurable domain " + strDomain + " not found";
274
275 return false;
276 }
277 // Delegate
278 return pConfigurableDomain->renameConfiguration(strConfigurationName, strNewConfigurationName, strError);
279}
280
281bool CConfigurableDomains::listDomainElements(const string& strDomain, string& strResult) const
282{
283 // Find domain
284 const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain));
285
286 if (!pConfigurableDomain) {
287
288 strResult = "Configurable domain " + strDomain + " not found";
289
290 return false;
291 }
292 // Delegate
293 pConfigurableDomain->listAssociatedToElements(strResult);
294
295 return true;
296}
297
298bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError)
299{
300 // Find domain
301 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
302
303 if (!pConfigurableDomain) {
304
305 strError = "Configurable domain " + strDomain + " not found";
306
307 return false;
308 }
309 // Delegate
310 pConfigurableDomain->split(pConfigurableElement, strError);
311
312 return true;
313}
314
315void CConfigurableDomains::listAssociatedElements(string& strResult) const
316{
317 strResult = "\n";
318
319 set<const CConfigurableElement*> configurableElementSet;
320
321 // Get all owned configurable elements
322 gatherAllOwnedConfigurableElements(configurableElementSet);
323
324 // Fill result
325 set<const CConfigurableElement*>::const_iterator it;
326
327 for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) {
328
329 const CConfigurableElement* pConfigurableElement = *it;
330
331 string strAssociatedDomainList;
332
333 pConfigurableElement->listAssociatedDomains(strAssociatedDomainList, false);
334
335 strResult += pConfigurableElement->getPath() + " [" + strAssociatedDomainList + "]\n";
336 }
337}
338
339void CConfigurableDomains::listConflictingElements(string& strResult) const
340{
341 strResult = "\n";
342
343 set<const CConfigurableElement*> configurableElementSet;
344
345 // Get all owned configurable elements
346 gatherAllOwnedConfigurableElements(configurableElementSet);
347
348 // Fill result
349 set<const CConfigurableElement*>::const_iterator it;
350
351 for (it = configurableElementSet.begin(); it != configurableElementSet.end(); ++it) {
352
353 const CConfigurableElement* pConfigurableElement = *it;
354
355 if (pConfigurableElement->getBelongingDomainCount() > 1) {
356
357 string strBelongingDomainList;
358
359 pConfigurableElement->listBelongingDomains(strBelongingDomainList, false);
360
361 strResult += pConfigurableElement->getPath() + " contained in multiple domains: " + strBelongingDomainList + "\n";
362 }
363 }
364}
365
Patrick Benavoli63499d42011-10-24 18:50:03 +0200366void CConfigurableDomains::listDomains(string& strResult) const
367{
368 strResult = "\n";
369
370 // List domains
371 uint32_t uiChild;
372 uint32_t uiNbConfigurableDomains = getNbChildren();
373
374 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
375
376 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
377
378 // Name
379 strResult += pChildConfigurableDomain->getName();
380
381 // Sequence awareness
382 if (pChildConfigurableDomain->getSequenceAwareness()) {
383
Patrick Benavoli9bed7ce2011-11-20 20:04:35 +0100384 strResult += " [sequence aware]";
Patrick Benavoli63499d42011-10-24 18:50:03 +0200385 }
Patrick Benavoli9bed7ce2011-11-20 20:04:35 +0100386 strResult += "\n";
Patrick Benavoli63499d42011-10-24 18:50:03 +0200387 }
388}
389
Patrick Benavoli68a91282011-08-31 11:23:23 +0200390// Gather configurable elements owned by any domain
391void CConfigurableDomains::gatherAllOwnedConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const
392{
393 // Delegate to domains
394 uint32_t uiChild;
395 uint32_t uiNbConfigurableDomains = getNbChildren();
396
397 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
398
399 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
400
401 pChildConfigurableDomain->gatherConfigurableElements(configurableElementSet);
402 }
403}
404
405// Config restore
406bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError)
407{
408 // Find domain
409 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
410
411 if (!pConfigurableDomain) {
412
413 strError = "Configurable domain " + strDomain + " not found";
414
415 return false;
416 }
417 // Delegate
418 return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, strError);
419}
420
421// Config save
422bool CConfigurableDomains::saveConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError)
423{
424 // Find domain
425 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
426
427 if (!pConfigurableDomain) {
428
429 strError = "Configurable domain " + strDomain + " not found";
430
431 return false;
432 }
433 // Delegate
434 return pConfigurableDomain->saveConfiguration(strConfiguration, pMainBlackboard, strError);
435}
436
Patrick Benavoli63499d42011-10-24 18:50:03 +0200437bool CConfigurableDomains::setElementSequence(const string& strDomain, const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError)
438{
439 // Find domain
440 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
441
442 if (!pConfigurableDomain) {
443
444 strError = "Configurable domain " + strDomain + " not found";
445
446 return false;
447 }
448
449 // Delegate to domain
450 return pConfigurableDomain->setElementSequence(strConfiguration, astrNewElementSequence, strError);
451}
452
453bool CConfigurableDomains::getElementSequence(const string& strDomain, const string& strConfiguration, string& strResult) const
454{
455 // Find domain
456 const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain));
457
458 if (!pConfigurableDomain) {
459
460 strResult = "Configurable domain " + strDomain + " not found";
461
462 return false;
463 }
464 // Delegate to domain
465 return pConfigurableDomain->getElementSequence(strConfiguration, strResult);
466}
467
Patrick Benavoli68a91282011-08-31 11:23:23 +0200468// Last applied configurations
469void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) const
470{
Patrick Benavoli68a91282011-08-31 11:23:23 +0200471 // Browse domains
472 uint32_t uiChild;
473 uint32_t uiNbConfigurableDomains = getNbChildren();
474
475 for (uiChild = 0; uiChild < uiNbConfigurableDomains; uiChild++) {
476
477 const CConfigurableDomain* pChildConfigurableDomain = static_cast<const CConfigurableDomain*>(getChild(uiChild));
478
479 strResult += pChildConfigurableDomain->getName() + ": " + pChildConfigurableDomain->getLastAppliedConfigurationName() + "\n";
480 }
481}
482
483// Configurable element - domain association
484bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError)
485{
486 // Find domain
487 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
488
489 if (!pConfigurableDomain) {
490
491 strError = "Configurable domain " + strDomain + " not found";
492
493 return false;
494 }
495 // Delegate
496 return pConfigurableDomain->addConfigurableElement(pConfigurableElement, pMainBlackboard, strError);
497}
498
499bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError)
500{
501 // Find domain
502 CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain));
503
504 if (!pConfigurableDomain) {
505
506 strError = "Configurable domain " + strDomain + " not found";
507
508 return false;
509 }
510 // Delegate
511 return pConfigurableDomain->removeConfigurableElement(pConfigurableElement, strError);
512}
513
514// Binary settings load/store
515bool 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}