blob: d3cd74019613ff81c5f8f88ed6303395e1719d06 [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +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
Frederic Boisnard390b36d2013-05-23 15:28:31 +020058// Returns the formatted mapping
59string CInstanceConfigurableElement::getFormattedMapping() const
60{
61 // Delegate
62 return getTypeElement()->getFormattedMapping();
63}
64
Patrick Benavoli68a91282011-08-31 11:23:23 +020065bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError)
66{
67 bool bHasMappingData = getTypeElement()->hasMappingData();
Kevin Rocard084cafb2013-01-28 17:02:08 +010068 bool bKeepDiving = true;
Patrick Benavoli68a91282011-08-31 11:23:23 +020069
70 // Begin
Kevin Rocard084cafb2013-01-28 17:02:08 +010071 if (bHasMappingData && !mapper.mapBegin(this, bKeepDiving, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020072
Kevin Rocard084cafb2013-01-28 17:02:08 +010073 return false;
Patrick Benavoli68a91282011-08-31 11:23:23 +020074 }
75
Kevin Rocard084cafb2013-01-28 17:02:08 +010076 // Go on through children?
77 if (bKeepDiving) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020078
Kevin Rocard084cafb2013-01-28 17:02:08 +010079 // Map children
80 uint32_t uiNbChildren = getNbChildren();
81 uint32_t uiChild;
Patrick Benavoli68a91282011-08-31 11:23:23 +020082
Kevin Rocard084cafb2013-01-28 17:02:08 +010083 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020084
Kevin Rocard3414f992013-04-02 19:49:40 +020085 CInstanceConfigurableElement* pInstanceConfigurableChildElement =
86 static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
Patrick Benavoli68a91282011-08-31 11:23:23 +020087
Kevin Rocard084cafb2013-01-28 17:02:08 +010088 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
89
90 return false;
91 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020092 }
93 }
94
95 // End
96 if (bHasMappingData) {
97
98 mapper.mapEnd();
99 }
100 return true;
101}
102
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +0200103void CInstanceConfigurableElement::getListOfElementsWithMapping(
104 list<const CConfigurableElement*>& configurableElementPath) const
105{
106 const CTypeElement* pTypeElement = getTypeElement();
107
108 if (pTypeElement && pTypeElement->hasMappingData()) {
109
110 configurableElementPath.push_back(this);
111 }
112
113 base::getListOfElementsWithMapping(configurableElementPath);
114}
115
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200116// Element properties
117void CInstanceConfigurableElement::showProperties(string& strResult) const
118{
119 base::showProperties(strResult);
120
121 // Delegate to type element
122 _pTypeElement->showProperties(strResult);
123}
124
Patrick Benavoli065264a2011-11-20 15:46:41 +0100125// Scalar or Array?
126bool CInstanceConfigurableElement::isScalar() const
127{
128 return _pTypeElement->isScalar();
129}
130
131// Array Length
132uint32_t CInstanceConfigurableElement::getArrayLength() const
133{
134 return _pTypeElement->getArrayLength();
135}
136
Patrick Benavoli68a91282011-08-31 11:23:23 +0200137// Sync to HW
138void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
139{
140 assert(!_pSyncer);
141
142 _pSyncer = pSyncer;
143}
144
145void CInstanceConfigurableElement::unsetSyncer()
146{
147 _pSyncer = NULL;
148}
149
150// Syncer
151ISyncer* CInstanceConfigurableElement::getSyncer() const
152{
153 if (_pSyncer) {
154
155 return _pSyncer;
156 }
157 // Check parent
158 return base::getSyncer();
159}
160
161// Syncer set (descendant)
162void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
163{
164 if (_pSyncer) {
165
166 syncerSet += _pSyncer;
167 } else {
168 // Continue digging
169 base::fillSyncerSetFromDescendant(syncerSet);
170 }
171}
172
173// Sync
174bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
175{
176 ISyncer* pSyncer = getSyncer();
177
178 if (!pSyncer) {
179
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200180 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200181
182 return false;
183 }
184 string strError;
185
186 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
187
188 parameterAccessContext.setError(strError);
189
190 return false;
191 }
192 return true;
193}
194
195// Check parameter access path well formed for leaf elements
196bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
197{
198 string* pStrChildName = pathNavigator.next();
199
200 if (pStrChildName) {
201
202 // Should be leaf element
203 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
204
205 return false;
206 }
207 return true;
208}
209