blob: 6795f8bc9e84c9488f5d98d7a50537b19d811a2d [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();
61
62 // Begin
63 if (bHasMappingData) {
64
Patrick Benavolid3a86bf2011-11-07 19:33:30 +010065 bool bKeepDiving;
66
67 if (!mapper.mapBegin(this, bKeepDiving, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020068
69 return false;
70 }
Patrick Benavolid3a86bf2011-11-07 19:33:30 +010071 // Go on through children?
72 if (!bKeepDiving) {
73
74 return true;
75 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020076 }
77
78 // Map children
79 uint32_t uiNbChildren = getNbChildren();
80 uint32_t uiChild;
81
82 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
83
84 CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
85
86 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
87
88 return false;
89 }
90 }
91
92 // End
93 if (bHasMappingData) {
94
95 mapper.mapEnd();
96 }
97 return true;
98}
99
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200100// Element properties
101void CInstanceConfigurableElement::showProperties(string& strResult) const
102{
103 base::showProperties(strResult);
104
105 // Delegate to type element
106 _pTypeElement->showProperties(strResult);
107}
108
Patrick Benavoli065264a2011-11-20 15:46:41 +0100109// Scalar or Array?
110bool CInstanceConfigurableElement::isScalar() const
111{
112 return _pTypeElement->isScalar();
113}
114
115// Array Length
116uint32_t CInstanceConfigurableElement::getArrayLength() const
117{
118 return _pTypeElement->getArrayLength();
119}
120
Patrick Benavoli68a91282011-08-31 11:23:23 +0200121// Sync to HW
122void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
123{
124 assert(!_pSyncer);
125
126 _pSyncer = pSyncer;
127}
128
129void CInstanceConfigurableElement::unsetSyncer()
130{
131 _pSyncer = NULL;
132}
133
134// Syncer
135ISyncer* CInstanceConfigurableElement::getSyncer() const
136{
137 if (_pSyncer) {
138
139 return _pSyncer;
140 }
141 // Check parent
142 return base::getSyncer();
143}
144
145// Syncer set (descendant)
146void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
147{
148 if (_pSyncer) {
149
150 syncerSet += _pSyncer;
151 } else {
152 // Continue digging
153 base::fillSyncerSetFromDescendant(syncerSet);
154 }
155}
156
157// Sync
158bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
159{
160 ISyncer* pSyncer = getSyncer();
161
162 if (!pSyncer) {
163
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200164 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200165
166 return false;
167 }
168 string strError;
169
170 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
171
172 parameterAccessContext.setError(strError);
173
174 return false;
175 }
176 return true;
177}
178
179// Check parameter access path well formed for leaf elements
180bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
181{
182 string* pStrChildName = pathNavigator.next();
183
184 if (pStrChildName) {
185
186 // Should be leaf element
187 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
188
189 return false;
190 }
191 return true;
192}
193