blob: 40ef18b3dad59e914a434c52730ee62379395fa0 [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "InstanceConfigurableElement.h"
26#include "Mapper.h"
27#include "SyncerSet.h"
28#include "Syncer.h"
29#include "TypeElement.h"
30#include "ParameterAccessContext.h"
31#include <assert.h>
32
33#define base CConfigurableElement
34
35CInstanceConfigurableElement::CInstanceConfigurableElement(const string& strName, const CTypeElement* pTypeElement) : base(strName), _pTypeElement(pTypeElement), _pSyncer(NULL)
36{
37}
38
39string CInstanceConfigurableElement::getKind() const
40{
41 // Delegate
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020042 return _pTypeElement->getKind();
Patrick Benavoli68a91282011-08-31 11:23:23 +020043}
44
45// Type element
46const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
47{
48 return _pTypeElement;
49}
50
51// Mapping
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020052bool CInstanceConfigurableElement::getMappingData(const string& strKey, const string*& pStrValue) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020053{
54 // Delegate
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020055 return getTypeElement()->getMappingData(strKey, pStrValue);
Patrick Benavoli68a91282011-08-31 11:23:23 +020056}
57
58bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError)
59{
60 bool bHasMappingData = getTypeElement()->hasMappingData();
Kevin Rocard084cafb2013-01-28 17:02:08 +010061 bool bKeepDiving = true;
Patrick Benavoli68a91282011-08-31 11:23:23 +020062
63 // Begin
Kevin Rocard084cafb2013-01-28 17:02:08 +010064 if (bHasMappingData && !mapper.mapBegin(this, bKeepDiving, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020065
Kevin Rocard084cafb2013-01-28 17:02:08 +010066 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +020067 }
68
Kevin Rocard084cafb2013-01-28 17:02:08 +010069 // Go on through children?
70 if (bKeepDiving) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020071
Kevin Rocard084cafb2013-01-28 17:02:08 +010072 // Map children
73 uint32_t uiNbChildren = getNbChildren();
74 uint32_t uiChild;
Patrick Benavoli68a91282011-08-31 11:23:23 +020075
Kevin Rocard084cafb2013-01-28 17:02:08 +010076 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020077
Kevin Rocard3414f992013-04-02 19:49:40 +020078 CInstanceConfigurableElement* pInstanceConfigurableChildElement =
79 static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
Patrick Benavoli68a91282011-08-31 11:23:23 +020080
Kevin Rocard084cafb2013-01-28 17:02:08 +010081 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
82
83 return false;
84 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020085 }
86 }
87
88 // End
89 if (bHasMappingData) {
90
91 mapper.mapEnd();
92 }
93 return true;
94}
95
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020096// Element properties
97void CInstanceConfigurableElement::showProperties(string& strResult) const
98{
99 base::showProperties(strResult);
100
101 // Delegate to type element
102 _pTypeElement->showProperties(strResult);
103}
104
Patrick Benavoli065264a2011-11-20 15:46:41 +0100105// Scalar or Array?
106bool CInstanceConfigurableElement::isScalar() const
107{
108 return _pTypeElement->isScalar();
109}
110
111// Array Length
112uint32_t CInstanceConfigurableElement::getArrayLength() const
113{
114 return _pTypeElement->getArrayLength();
115}
116
Patrick Benavoli68a91282011-08-31 11:23:23 +0200117// Sync to HW
118void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
119{
120 assert(!_pSyncer);
121
122 _pSyncer = pSyncer;
123}
124
125void CInstanceConfigurableElement::unsetSyncer()
126{
127 _pSyncer = NULL;
128}
129
130// Syncer
131ISyncer* CInstanceConfigurableElement::getSyncer() const
132{
133 if (_pSyncer) {
134
135 return _pSyncer;
136 }
137 // Check parent
138 return base::getSyncer();
139}
140
141// Syncer set (descendant)
142void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
143{
144 if (_pSyncer) {
145
146 syncerSet += _pSyncer;
147 } else {
148 // Continue digging
149 base::fillSyncerSetFromDescendant(syncerSet);
150 }
151}
152
153// Sync
154bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
155{
156 ISyncer* pSyncer = getSyncer();
157
158 if (!pSyncer) {
159
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200160 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200161
162 return false;
163 }
164 string strError;
165
166 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
167
168 parameterAccessContext.setError(strError);
169
170 return false;
171 }
172 return true;
173}
174
175// Check parameter access path well formed for leaf elements
176bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
177{
178 string* pStrChildName = pathNavigator.next();
179
180 if (pStrChildName) {
181
182 // Should be leaf element
183 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
184
185 return false;
186 }
187 return true;
188}
189