| Kevin Rocard | 93250d1 | 2012-07-19 17:48:30 +0200 | [diff] [blame] | 1 | /* |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 2 | * 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 22 | * CREATED: 2011-06-01 |
| 23 | * UPDATED: 2011-07-27 |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 24 | */ |
| 25 | #include "BitParameter.h" |
| 26 | #include "BitParameterType.h" |
| 27 | #include "ParameterAccessContext.h" |
| 28 | #include "ConfigurationAccessContext.h" |
| 29 | #include "ParameterBlackboard.h" |
| 30 | #include "BitParameterBlock.h" |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 31 | #include "BitwiseAreaConfiguration.h" |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 32 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 33 | #define base CBaseParameter |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 34 | |
| 35 | CBitParameter::CBitParameter(const string& strName, const CTypeElement* pTypeElement) : base(strName, pTypeElement) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | // Type |
| 40 | CInstanceConfigurableElement::Type CBitParameter::getType() const |
| 41 | { |
| 42 | return EBitParameter; |
| 43 | } |
| 44 | |
| 45 | // Size |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 46 | uint32_t CBitParameter::getBelongingBlockSize() const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 47 | { |
| 48 | return static_cast<const CBitParameterBlock*>(getParent())->getSize(); |
| 49 | } |
| 50 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 51 | // Instantiation, allocation |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 52 | uint32_t CBitParameter::getFootPrint() const |
| 53 | { |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 54 | // Allocation done at parent level |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 58 | // Actual parameter access (tuning) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 59 | bool CBitParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 60 | { |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 61 | return doSet(strValue, uiOffset, parameterAccessContext); |
| 62 | } |
| 63 | |
| 64 | void CBitParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 65 | { |
| 66 | doGet(strValue, uiOffset, parameterAccessContext); |
| 67 | } |
| 68 | |
| 69 | /// Value access |
| 70 | // Boolean access |
| 71 | bool CBitParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 72 | { |
| 73 | // Check boolean access validity here |
| 74 | if (static_cast<const CBitParameterType*>(getTypeElement())->getBitSize() != 1) { |
| 75 | |
| 76 | parameterAccessContext.setError("Type mismatch"); |
| 77 | // Append parameter path to error |
| 78 | parameterAccessContext.appendToError(" " + getPath()); |
| 79 | |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | // Rely on integer access |
| Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame^] | 84 | uint64_t uiValue; |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 85 | |
| 86 | if (bSet) { |
| 87 | |
| 88 | uiValue = bValue; |
| 89 | } |
| 90 | |
| 91 | if (!accessAsInteger(uiValue, bSet, parameterAccessContext)) { |
| 92 | |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | if (!bSet) { |
| 97 | |
| 98 | bValue = uiValue != 0; |
| 99 | } |
| 100 | |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | // Integer Access |
| Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame^] | 105 | bool CBitParameter::accessAsInteger(uint64_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 106 | { |
| 107 | uint32_t uiOffset = getOffset(); |
| 108 | |
| 109 | if (bSet) { |
| 110 | |
| 111 | // Set and sync |
| 112 | if (!doSet(uiValue, uiOffset, parameterAccessContext) || !sync(parameterAccessContext)) { |
| 113 | |
| 114 | // Append parameter path to error |
| 115 | parameterAccessContext.appendToError(" " + getPath()); |
| 116 | |
| 117 | return false; |
| 118 | } |
| 119 | } else { |
| 120 | |
| 121 | // Convert |
| 122 | doGet(uiValue, uiOffset, parameterAccessContext); |
| 123 | } |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | template <typename type> |
| 128 | bool CBitParameter::doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 129 | { |
| Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame^] | 130 | uint64_t uiData = 0; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 131 | |
| 132 | // Read/modify/write |
| 133 | CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 134 | |
| 135 | // Beware this code works on little endian architectures only! |
| Patrick Benavoli | 1352ae5 | 2011-10-21 16:48:04 +0200 | [diff] [blame] | 136 | pBlackboard->readInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 137 | |
| 138 | // Convert |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 139 | if (!static_cast<const CBitParameterType*>(getTypeElement())->toBlackboard(value, uiData, parameterAccessContext)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 140 | |
| 141 | return false; |
| 142 | } |
| 143 | // Write blackboard |
| Patrick Benavoli | 1352ae5 | 2011-10-21 16:48:04 +0200 | [diff] [blame] | 144 | pBlackboard->writeInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 145 | |
| 146 | return true; |
| 147 | } |
| 148 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 149 | template <typename type> |
| 150 | void CBitParameter::doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 151 | { |
| Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame^] | 152 | uint64_t uiData = 0; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 153 | |
| 154 | // Read blackboard |
| Patrick Benavoli | 1352ae5 | 2011-10-21 16:48:04 +0200 | [diff] [blame] | 155 | const CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 156 | |
| 157 | // Beware this code works on little endian architectures only! |
| Patrick Benavoli | 1352ae5 | 2011-10-21 16:48:04 +0200 | [diff] [blame] | 158 | pBlackboard->readInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 159 | |
| 160 | // Convert |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame] | 161 | static_cast<const CBitParameterType*>(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 162 | } |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 163 | |
| 164 | // AreaConfiguration creation |
| 165 | CAreaConfiguration* CBitParameter::createAreaConfiguration(const CSyncerSet* pSyncerSet) const |
| 166 | { |
| 167 | return new CBitwiseAreaConfiguration(this, pSyncerSet); |
| 168 | } |
| 169 | |
| 170 | // Access from area configuration |
| Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame^] | 171 | uint64_t CBitParameter::merge(uint64_t uiOriginData, uint64_t uiNewData) const |
| Frédéric Boisnard | 9620e44 | 2012-05-30 16:15:02 +0200 | [diff] [blame] | 172 | { |
| 173 | // Convert |
| 174 | return static_cast<const CBitParameterType*>(getTypeElement())->merge(uiOriginData, uiNewData); |
| 175 | } |