blob: 4a6cacc5790c8c794e901c10db878658a5e43fbd [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 Rocard084cafb2013-01-28 17:02:08 +010078 CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
Patrick Benavoli68a91282011-08-31 11:23:23 +020079
Kevin Rocard084cafb2013-01-28 17:02:08 +010080 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
81
82 return false;
83 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020084 }
85 }
86
87 // End
88 if (bHasMappingData) {
89
90 mapper.mapEnd();
91 }
92 return true;
93}
94
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020095// Element properties
96void CInstanceConfigurableElement::showProperties(string& strResult) const
97{
98 base::showProperties(strResult);
99
100 // Delegate to type element
101 _pTypeElement->showProperties(strResult);
102}
103
Patrick Benavoli065264a2011-11-20 15:46:41 +0100104// Scalar or Array?
105bool CInstanceConfigurableElement::isScalar() const
106{
107 return _pTypeElement->isScalar();
108}
109
110// Array Length
111uint32_t CInstanceConfigurableElement::getArrayLength() const
112{
113 return _pTypeElement->getArrayLength();
114}
115
Patrick Benavoli68a91282011-08-31 11:23:23 +0200116// Sync to HW
117void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
118{
119 assert(!_pSyncer);
120
121 _pSyncer = pSyncer;
122}
123
124void CInstanceConfigurableElement::unsetSyncer()
125{
126 _pSyncer = NULL;
127}
128
129// Syncer
130ISyncer* CInstanceConfigurableElement::getSyncer() const
131{
132 if (_pSyncer) {
133
134 return _pSyncer;
135 }
136 // Check parent
137 return base::getSyncer();
138}
139
140// Syncer set (descendant)
141void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
142{
143 if (_pSyncer) {
144
145 syncerSet += _pSyncer;
146 } else {
147 // Continue digging
148 base::fillSyncerSetFromDescendant(syncerSet);
149 }
150}
151
152// Sync
153bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
154{
155 ISyncer* pSyncer = getSyncer();
156
157 if (!pSyncer) {
158
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200159 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200160
161 return false;
162 }
163 string strError;
164
165 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
166
167 parameterAccessContext.setError(strError);
168
169 return false;
170 }
171 return true;
172}
173
174// Check parameter access path well formed for leaf elements
175bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
176{
177 string* pStrChildName = pathNavigator.next();
178
179 if (pStrChildName) {
180
181 // Should be leaf element
182 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
183
184 return false;
185 }
186 return true;
187}
188