blob: cb7547726d6da5ece0acef5009249f64a5978946 [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 "BitParameter.h"
32#include "BitParameterType.h"
33#include "ParameterAccessContext.h"
34#include "ConfigurationAccessContext.h"
35#include "ParameterBlackboard.h"
36#include "BitParameterBlock.h"
37
38#define base CInstanceConfigurableElement
39
40CBitParameter::CBitParameter(const string& strName, const CTypeElement* pTypeElement) : base(strName, pTypeElement)
41{
42}
43
44// Type
45CInstanceConfigurableElement::Type CBitParameter::getType() const
46{
47 return EBitParameter;
48}
49
50// Size
51uint32_t CBitParameter::getSize() const
52{
53 return static_cast<const CBitParameterBlock*>(getParent())->getSize();
54}
55
56// XML configuration settings parsing/composing
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020057bool CBitParameter::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020058{
59 // Handle access
60 if (!configurationAccessContext.serializeOut()) {
61
62 // Write to blackboard
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020063 if (!doSetValue(xmlConfigurationSettingsElementContent.getTextContent(), getOffset() - configurationAccessContext.getBaseOffset(), configurationAccessContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020064
65 // Append parameter path to error
66 configurationAccessContext.appendToError(" " + getPath());
67
68 return false;
69 }
70 } else {
71
72 // Get string value
73 string strValue;
74
75 doGetValue(strValue, getOffset() - configurationAccessContext.getBaseOffset(), configurationAccessContext);
76
77 // Populate value into xml text node
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020078 xmlConfigurationSettingsElementContent.setTextContent(strValue);
Patrick Benavoli68a91282011-08-31 11:23:23 +020079 }
80
81 // Done
82 return true;
83}
84
85uint32_t CBitParameter::getFootPrint() const
86{
87 // Allocation made on parent side
88 return 0;
89}
90
91// Dump
92void CBitParameter::logValue(string& strValue, CErrorContext& errorContext) const
93{
94 CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext);
95
96 // Dump value
97 doGetValue(strValue, getOffset(), parameterContext);
98}
99
100// Parameter Access
101bool CBitParameter::setValue(CPathNavigator& pathNavigator, const string& strValue, CErrorContext& errorContext) const
102{
103 // Check path validity
104 if (!checkPathExhausted(pathNavigator, errorContext)) {
105
106 return false;
107 }
108 // Parameter context
109 CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext);
110
111 // Set Value
112 if (!doSetValue(strValue, getOffset(), parameterContext)) {
113
114 // Append parameter path to error
115 parameterContext.appendToError(" " + getPath());
116
117 return false;
118 }
119 // Synchronize
120 if (!sync(parameterContext)) {
121
122 // Append parameter path to error
123 parameterContext.appendToError(" " + getPath());
124
125 return false;
126 }
127 return true;
128}
129
130bool CBitParameter::getValue(CPathNavigator& pathNavigator, string& strValue, CErrorContext& errorContext) const
131{
132 // Check path validity
133 if (!checkPathExhausted(pathNavigator, errorContext)) {
134
135 return false;
136 }
137 // Parameter context
138 CParameterAccessContext& parameterContext = static_cast<CParameterAccessContext&>(errorContext);
139
140 // Get Value
141 doGetValue(strValue, getOffset(), parameterContext);
142
143 return true;
144}
145
146bool CBitParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
147{
148 uint32_t uiData = 0;
149
150 // Read/modify/write
151 CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard();
152
153 // Beware this code works on little endian architectures only!
154 pBlackboard->read(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem());
155
156 // Convert
157 if (!static_cast<const CBitParameterType*>(getTypeElement())->asInteger(strValue, uiData, parameterAccessContext)) {
158
159 return false;
160 }
161 // Write blackboard
162 pBlackboard->write(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem());
163
164 return true;
165}
166
167void CBitParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
168{
169 uint32_t uiData = 0;
170
171 // Read blackboard
172 CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard();
173
174 // Beware this code works on little endian architectures only!
175 pBlackboard->read(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem());
176
177 // Convert
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200178 static_cast<const CBitParameterType*>(getTypeElement())->asString(uiData, strValue, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200179}
180