blob: 9dcc2eff541ff866b5b76dbf9e1f2bf23456edfe [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
48 return getTypeElement()->getKind();
49}
50
51// Type element
52const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
53{
54 return _pTypeElement;
55}
56
57// Mapping
58bool CInstanceConfigurableElement::getMappingData(const string& strKey, string& strValue) const
59{
60 // Delegate
61 return getTypeElement()->getMappingData(strKey, strValue);
62}
63
64bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError)
65{
66 bool bHasMappingData = getTypeElement()->hasMappingData();
67
68 // Begin
69 if (bHasMappingData) {
70
71 if (!mapper.mapBegin(this, strError)) {
72
73 return false;
74 }
75 }
76
77 // Map children
78 uint32_t uiNbChildren = getNbChildren();
79 uint32_t uiChild;
80
81 for (uiChild = 0; uiChild < uiNbChildren; uiChild++) {
82
83 CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild));
84
85 if (!pInstanceConfigurableChildElement->map(mapper, strError)) {
86
87 return false;
88 }
89 }
90
91 // End
92 if (bHasMappingData) {
93
94 mapper.mapEnd();
95 }
96 return true;
97}
98
99// Sync to HW
100void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer)
101{
102 assert(!_pSyncer);
103
104 _pSyncer = pSyncer;
105}
106
107void CInstanceConfigurableElement::unsetSyncer()
108{
109 _pSyncer = NULL;
110}
111
112// Syncer
113ISyncer* CInstanceConfigurableElement::getSyncer() const
114{
115 if (_pSyncer) {
116
117 return _pSyncer;
118 }
119 // Check parent
120 return base::getSyncer();
121}
122
123// Syncer set (descendant)
124void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const
125{
126 if (_pSyncer) {
127
128 syncerSet += _pSyncer;
129 } else {
130 // Continue digging
131 base::fillSyncerSetFromDescendant(syncerSet);
132 }
133}
134
135// Sync
136bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const
137{
138 ISyncer* pSyncer = getSyncer();
139
140 if (!pSyncer) {
141
142 parameterAccessContext.setError("Unable to synchronize modification. No Syncer object assiciated to configurable element " + getPath());
143
144 return false;
145 }
146 string strError;
147
148 if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) {
149
150 parameterAccessContext.setError(strError);
151
152 return false;
153 }
154 return true;
155}
156
157// Check parameter access path well formed for leaf elements
158bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext)
159{
160 string* pStrChildName = pathNavigator.next();
161
162 if (pStrChildName) {
163
164 // Should be leaf element
165 errorContext.setError("Path not found: " + pathNavigator.getCurrentPath());
166
167 return false;
168 }
169 return true;
170}
171