blob: 098fe8f4df2540d1e874be1acac7e3f4e506ae03 [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001/*
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 */
30#include "InstanceConfigurableElement.h"
31#include "Mapper.h"
32#include "SyncerSet.h"
33#include "Syncer.h"
34#include "TypeElement.h"
35#include "ParameterAccessContext.h"
36#include <assert.h>
37
38#define base CConfigurableElement
39
40CInstanceConfigurableElement::CInstanceConfigurableElement(const string& strName, const CTypeElement* pTypeElement) : base(strName), _pTypeElement(pTypeElement), _pSyncer(NULL)
41{
42}
43
44string CInstanceConfigurableElement::getKind() const
45{
46 // Delegate
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020047 return _pTypeElement->getKind();
Patrick Benavoli68a91282011-08-31 11:23:23 +020048}
49
50// Type element
51const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
52{
53 return _pTypeElement;
54}
55
56// Mapping
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020057bool CInstanceConfigurableElement::getMappingData(const string& strKey, const string*& pStrValue) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020058{
59 // Delegate
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020060 return getTypeElement()->getMappingData(strKey, pStrValue);
Patrick Benavoli68a91282011-08-31 11:23:23 +020061}
62
Frederic Boisnard390b36d2013-05-23 15:28:31 +020063// Returns the formatted mapping
64string CInstanceConfigurableElement::getFormattedMapping() const
65{
66 // Delegate
67 return getTypeElement()->getFormattedMapping();
68}
69
Patrick Benavoli68a91282011-08-31 11:23:23 +020070bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError)
71{
72 bool bHasMappingData = getTypeElement()->hasMappingData();
Kevin Rocard084cafb2013-01-28 17:02:08 +010073 bool bKeepDiving = true;
Patrick Benavoli68a91282011-08-31 11:23:23 +020074
75 // Begin
Kevin Rocard084cafb2013-01-28 17:02:08 +010076 if (bHasMappingData && !mapper.mapBegin(this, bKeepDiving, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020077
Kevin Rocard084cafb2013-01-28 17:02:08 +010078 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +020079 }
80
Kevin Rocard084cafb2013-01-28 17:02:08 +010081 // Go on through children?
82 if (bKeepDiving) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020083
Kevin Rocard084cafb2013-01-28 17:02:08 +010084 // Map children
85 uint32_t uiNbChildren = getNbChildren();
86 uint32_t uiChild;
Patrick Benavoli68a91282011-08-31 11:23:23 +020087
Kevin Rocard084cafb2013-01-28 17:02:08 +010088 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020089
Kevin Rocard3414f992013-04-02 19:49:40 +020090 CInstanceConfigurableElement* pInstanceConfigurableChildElement =
91 static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
Patrick Benavoli68a91282011-08-31 11:23:23 +020092
Kevin Rocard084cafb2013-01-28 17:02:08 +010093 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
94
95 return false;
96 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020097 }
98 }
99
100 // End
101 if (bHasMappingData) {
102
103 mapper.mapEnd();
104 }
105 return true;
106}
107
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200108void CInstanceConfigurableElement::getListOfElementsWithMapping(
109 list<const CConfigurableElement*>& configurableElementPath) const
110{
111 const CTypeElement* pTypeElement = getTypeElement();
112
113 if (pTypeElement && pTypeElement->hasMappingData()) {
114
115 configurableElementPath.push_back(this);
116 }
117
118 base::getListOfElementsWithMapping(configurableElementPath);
119}
120
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200121// Element properties
122void CInstanceConfigurableElement::showProperties(string& strResult) const
123{
124 base::showProperties(strResult);
125
126 // Delegate to type element
127 _pTypeElement->showProperties(strResult);
128}
129
Patrick Benavoli065264a2011-11-20 15:46:41 +0100130// Scalar or Array?
131bool CInstanceConfigurableElement::isScalar() const
132{
133 return _pTypeElement->isScalar();
134}
135
136// Array Length
137uint32_t CInstanceConfigurableElement::getArrayLength() const
138{
139 return _pTypeElement->getArrayLength();
140}
141
Patrick Benavoli68a91282011-08-31 11:23:23 +0200142// Sync to HW
143void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
144{
145 assert(!_pSyncer);
146
147 _pSyncer = pSyncer;
148}
149
150void CInstanceConfigurableElement::unsetSyncer()
151{
152 _pSyncer = NULL;
153}
154
155// Syncer
156ISyncer* CInstanceConfigurableElement::getSyncer() const
157{
158 if (_pSyncer) {
159
160 return _pSyncer;
161 }
162 // Check parent
163 return base::getSyncer();
164}
165
166// Syncer set (descendant)
167void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
168{
169 if (_pSyncer) {
170
171 syncerSet += _pSyncer;
172 } else {
173 // Continue digging
174 base::fillSyncerSetFromDescendant(syncerSet);
175 }
176}
177
178// Sync
179bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
180{
181 ISyncer* pSyncer = getSyncer();
182
183 if (!pSyncer) {
184
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200185 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200186
187 return false;
188 }
189 string strError;
190
191 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
192
193 parameterAccessContext.setError(strError);
194
195 return false;
196 }
197 return true;
198}
199
200// Check parameter access path well formed for leaf elements
201bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
202{
203 string* pStrChildName = pathNavigator.next();
204
205 if (pStrChildName) {
206
207 // Should be leaf element
208 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
209
210 return false;
211 }
212 return true;
213}
214