blob: cc84a3ed190e642b48a86efb93f71dcc3513f2b4 [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
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
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200103// Element properties
104void CInstanceConfigurableElement::showProperties(string& strResult) const
105{
106 base::showProperties(strResult);
107
108 // Delegate to type element
109 _pTypeElement->showProperties(strResult);
110}
111
Patrick Benavoli065264a2011-11-20 15:46:41 +0100112// Scalar or Array?
113bool CInstanceConfigurableElement::isScalar() const
114{
115 return _pTypeElement->isScalar();
116}
117
118// Array Length
119uint32_t CInstanceConfigurableElement::getArrayLength() const
120{
121 return _pTypeElement->getArrayLength();
122}
123
Patrick Benavoli68a91282011-08-31 11:23:23 +0200124// Sync to HW
125void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
126{
127 assert(!_pSyncer);
128
129 _pSyncer = pSyncer;
130}
131
132void CInstanceConfigurableElement::unsetSyncer()
133{
134 _pSyncer = NULL;
135}
136
137// Syncer
138ISyncer* CInstanceConfigurableElement::getSyncer() const
139{
140 if (_pSyncer) {
141
142 return _pSyncer;
143 }
144 // Check parent
145 return base::getSyncer();
146}
147
148// Syncer set (descendant)
149void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
150{
151 if (_pSyncer) {
152
153 syncerSet += _pSyncer;
154 } else {
155 // Continue digging
156 base::fillSyncerSetFromDescendant(syncerSet);
157 }
158}
159
160// Sync
161bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
162{
163 ISyncer* pSyncer = getSyncer();
164
165 if (!pSyncer) {
166
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200167 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200168
169 return false;
170 }
171 string strError;
172
173 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
174
175 parameterAccessContext.setError(strError);
176
177 return false;
178 }
179 return true;
180}
181
182// Check parameter access path well formed for leaf elements
183bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
184{
185 string* pStrChildName = pathNavigator.next();
186
187 if (pStrChildName) {
188
189 // Should be leaf element
190 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
191
192 return false;
193 }
194 return true;
195}
196