blob: 8720fef3283f903e3df3c3901f3adeed241211be [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <auto_header>
2 * <FILENAME>
3 *
4 * INTEL CONFIDENTIAL
5 * Copyright © 2011 Intel
6 * Corporation All Rights Reserved.
7 *
8 * The source code contained or described herein and all documents related to
9 * the source code ("Material") are owned by Intel Corporation or its suppliers
10 * or licensors. Title to the Material remains with Intel Corporation or its
11 * suppliers and licensors. The Material contains trade secrets and proprietary
12 * and confidential information of Intel or its suppliers and licensors. The
13 * Material is protected by worldwide copyright and trade secret laws and
14 * treaty provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed, or
16 * disclosed in any way without Intel’s prior express written permission.
17 *
18 * No license under any patent, copyright, trade secret or other intellectual
19 * property right is granted to or conferred upon you by disclosure or delivery
20 * of the Materials, either expressly, by implication, inducement, estoppel or
21 * otherwise. Any license under such intellectual property rights must be
22 * express and approved by Intel in writing.
23 *
24 * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
25 * CREATED: 2011-06-01
26 * UPDATED: 2011-07-27
27 *
28 *
29 * </auto_header>
30 */
31#include "InstanceConfigurableElement.h"
32#include "Mapper.h"
33#include "SyncerSet.h"
34#include "Syncer.h"
35#include "TypeElement.h"
36#include "ParameterAccessContext.h"
37#include <assert.h>
38
39#define base CConfigurableElement
40
41CInstanceConfigurableElement::CInstanceConfigurableElement(const string& strName, const CTypeElement* pTypeElement) : base(strName), _pTypeElement(pTypeElement), _pSyncer(NULL)
42{
43}
44
45string CInstanceConfigurableElement::getKind() const
46{
47 // Delegate
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020048 return _pTypeElement->getKind();
Patrick Benavoli68a91282011-08-31 11:23:23 +020049}
50
51// Type element
52const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
53{
54 return _pTypeElement;
55}
56
57// Mapping
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020058bool CInstanceConfigurableElement::getMappingData(const string& strKey, const string*& pStrValue) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020059{
60 // Delegate
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020061 return getTypeElement()->getMappingData(strKey, pStrValue);
Patrick Benavoli68a91282011-08-31 11:23:23 +020062}
63
64bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError)
65{
66 bool bHasMappingData = getTypeElement()->hasMappingData();
67
68 // Begin
69 if (bHasMappingData) {
70
Patrick Benavolid3a86bf2011-11-07 19:33:30 +010071 bool bKeepDiving;
72
73 if (!mapper.mapBegin(this, bKeepDiving, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020074
75 return false;
76 }
Patrick Benavolid3a86bf2011-11-07 19:33:30 +010077 // Go on through children?
78 if (!bKeepDiving) {
79
80 return true;
81 }
Patrick Benavoli68a91282011-08-31 11:23:23 +020082 }
83
84 // Map children
85 uint32_t uiNbChildren = getNbChildren();
86 uint32_t uiChild;
87
88 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
89
90 CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
91
92 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
93
94 return false;
95 }
96 }
97
98 // End
99 if (bHasMappingData) {
100
101 mapper.mapEnd();
102 }
103 return true;
104}
105
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200106// Element properties
107void CInstanceConfigurableElement::showProperties(string& strResult) const
108{
109 base::showProperties(strResult);
110
111 // Delegate to type element
112 _pTypeElement->showProperties(strResult);
113}
114
Patrick Benavoli065264a2011-11-20 15:46:41 +0100115// Scalar or Array?
116bool CInstanceConfigurableElement::isScalar() const
117{
118 return _pTypeElement->isScalar();
119}
120
121// Array Length
122uint32_t CInstanceConfigurableElement::getArrayLength() const
123{
124 return _pTypeElement->getArrayLength();
125}
126
Patrick Benavoli68a91282011-08-31 11:23:23 +0200127// Sync to HW
128void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
129{
130 assert(!_pSyncer);
131
132 _pSyncer = pSyncer;
133}
134
135void CInstanceConfigurableElement::unsetSyncer()
136{
137 _pSyncer = NULL;
138}
139
140// Syncer
141ISyncer* CInstanceConfigurableElement::getSyncer() const
142{
143 if (_pSyncer) {
144
145 return _pSyncer;
146 }
147 // Check parent
148 return base::getSyncer();
149}
150
151// Syncer set (descendant)
152void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
153{
154 if (_pSyncer) {
155
156 syncerSet += _pSyncer;
157 } else {
158 // Continue digging
159 base::fillSyncerSetFromDescendant(syncerSet);
160 }
161}
162
163// Sync
164bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
165{
166 ISyncer* pSyncer = getSyncer();
167
168 if (!pSyncer) {
169
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200170 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:");
Patrick Benavoli68a91282011-08-31 11:23:23 +0200171
172 return false;
173 }
174 string strError;
175
176 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
177
178 parameterAccessContext.setError(strError);
179
180 return false;
181 }
182 return true;
183}
184
185// Check parameter access path well formed for leaf elements
186bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
187{
188 string* pStrChildName = pathNavigator.next();
189
190 if (pStrChildName) {
191
192 // Should be leaf element
193 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
194
195 return false;
196 }
197 return true;
198}
199