blob: f35be87dec60485672f440a86f6d65b414505f46 [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 "InstanceConfigurableElement.h"
32#include "Mapper.h"
33#include "SyncerSet.h"
34#include "Syncer.h"
35#include "TypeElement.h"
36#include "ParameterAccessContext.h"
37#include <assert.h>
38
39#define base CConfigurableElement
40
41CInstanceConfigurableElement::CInstanceConfigurableElement(const string& strName, const CTypeElement* pTypeElement) : base(strName), _pTypeElement(pTypeElement), _pSyncer(NULL)
42{
43}
44
45string CInstanceConfigurableElement::getKind() const
46{
47 // Delegate
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020048 return _pTypeElement->getKind();
Patrick Benavoli68a91282011-08-31 11:23:23 +020049}
50
51// Type element
52const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
53{
54 return _pTypeElement;
55}
56
57// Mapping
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020058bool CInstanceConfigurableElement::getMappingData(const string& strKey, const string*& pStrValue) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020059{
60 // Delegate
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020061 return getTypeElement()->getMappingData(strKey, pStrValue);
Patrick Benavoli68a91282011-08-31 11:23:23 +020062}
63
64bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError)
65{
66 bool bHasMappingData = getTypeElement()->hasMappingData();
67
68 // Begin
69 if (bHasMappingData) {
70
71 if (!mapper.mapBegin(this, strError)) {
72
73 return false;
74 }
75 }
76
77 // Map children
78 uint32_t uiNbChildren = getNbChildren();
79 uint32_t uiChild;
80
81 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
82
83 CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
84
85 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
86
87 return false;
88 }
89 }
90
91 // End
92 if (bHasMappingData) {
93
94 mapper.mapEnd();
95 }
96 return true;
97}
98
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020099// Element properties
100void CInstanceConfigurableElement::showProperties(string& strResult) const
101{
102 base::showProperties(strResult);
103
104 // Delegate to type element
105 _pTypeElement->showProperties(strResult);
106}
107
Patrick Benavoli68a91282011-08-31 11:23:23 +0200108// Sync to HW
109void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
110{
111 assert(!_pSyncer);
112
113 _pSyncer = pSyncer;
114}
115
116void CInstanceConfigurableElement::unsetSyncer()
117{
118 _pSyncer = NULL;
119}
120
121// Syncer
122ISyncer* CInstanceConfigurableElement::getSyncer() const
123{
124 if (_pSyncer) {
125
126 return _pSyncer;
127 }
128 // Check parent
129 return base::getSyncer();
130}
131
132// Syncer set (descendant)
133void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
134{
135 if (_pSyncer) {
136
137 syncerSet += _pSyncer;
138 } else {
139 // Continue digging
140 base::fillSyncerSetFromDescendant(syncerSet);
141 }
142}
143
144// Sync
145bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
146{
147 ISyncer* pSyncer = getSyncer();
148
149 if (!pSyncer) {
150
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200151 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200152
153 return false;
154 }
155 string strError;
156
157 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
158
159 parameterAccessContext.setError(strError);
160
161 return false;
162 }
163 return true;
164}
165
166// Check parameter access path well formed for leaf elements
167bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
168{
169 string* pStrChildName = pathNavigator.next();
170
171 if (pStrChildName) {
172
173 // Should be leaf element
174 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
175
176 return false;
177 }
178 return true;
179}
180