Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame^] | 1 | /* <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 "ParameterBlackboard.h" |
| 32 | #include <string.h> |
| 33 | #include <assert.h> |
| 34 | |
| 35 | CParameterBlackboard::CParameterBlackboard() : _puiData(NULL), _uiSize(0) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | CParameterBlackboard::~CParameterBlackboard() |
| 40 | { |
| 41 | delete [] _puiData; |
| 42 | } |
| 43 | |
| 44 | // Size |
| 45 | void CParameterBlackboard::setSize(uint32_t uiSize) |
| 46 | { |
| 47 | if (_puiData) { |
| 48 | |
| 49 | delete [] _puiData; |
| 50 | } |
| 51 | |
| 52 | _puiData = new uint8_t[uiSize]; |
| 53 | |
| 54 | memset(_puiData, 0, uiSize); |
| 55 | |
| 56 | _uiSize = uiSize; |
| 57 | } |
| 58 | |
| 59 | uint32_t CParameterBlackboard::getSize() const |
| 60 | { |
| 61 | return _uiSize; |
| 62 | } |
| 63 | |
| 64 | // Single parameter access |
| 65 | void CParameterBlackboard::write(const void* pvSrcData, uint32_t uiSize, uint32_t uiOffset, bool bBigEndian) |
| 66 | { |
| 67 | assert(uiSize + uiOffset <= _uiSize); |
| 68 | |
| 69 | if (!bBigEndian) { |
| 70 | |
| 71 | memcpy(_puiData + uiOffset, pvSrcData, uiSize); |
| 72 | } else { |
| 73 | |
| 74 | uint32_t uiIndex; |
| 75 | const uint8_t* puiSrcData = (const uint8_t*)pvSrcData; |
| 76 | |
| 77 | for (uiIndex = 0; uiIndex < uiSize; uiIndex++) { |
| 78 | |
| 79 | _puiData[uiIndex + uiOffset] = puiSrcData[uiSize - uiIndex - 1]; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void CParameterBlackboard::read(void* pvDstData, uint32_t uiSize, uint32_t uiOffset, bool bBigEndian) const |
| 85 | { |
| 86 | assert(uiSize + uiOffset <= _uiSize); |
| 87 | |
| 88 | if (!bBigEndian) { |
| 89 | |
| 90 | memcpy(pvDstData, _puiData + uiOffset, uiSize); |
| 91 | } else { |
| 92 | |
| 93 | uint32_t uiIndex; |
| 94 | uint8_t* puiDstData = (uint8_t*)pvDstData; |
| 95 | |
| 96 | for (uiIndex = 0; uiIndex < uiSize; uiIndex++) { |
| 97 | |
| 98 | puiDstData[uiSize - uiIndex - 1] = _puiData[uiIndex + uiOffset]; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Access from/to subsystems |
| 104 | void CParameterBlackboard::rawRead(void* pvDstData, uint32_t uiSize, uint32_t uiOffset) const |
| 105 | { |
| 106 | assert(uiSize + uiOffset <= _uiSize); |
| 107 | |
| 108 | memcpy(pvDstData, _puiData + uiOffset, uiSize); |
| 109 | } |
| 110 | |
| 111 | void CParameterBlackboard::rawWrite(const void* pvDstData, uint32_t uiSize, uint32_t uiOffset) |
| 112 | { |
| 113 | assert(uiSize + uiOffset <= _uiSize); |
| 114 | |
| 115 | memcpy(_puiData + uiOffset, pvDstData, uiSize); |
| 116 | } |
| 117 | |
| 118 | // Configuration handling |
| 119 | void CParameterBlackboard::restoreFrom(const CParameterBlackboard* pFromBlackboard, uint32_t uiOffset) |
| 120 | { |
| 121 | memcpy(_puiData + uiOffset, pFromBlackboard->_puiData, pFromBlackboard->_uiSize); |
| 122 | } |
| 123 | |
| 124 | void CParameterBlackboard::saveTo(CParameterBlackboard* pToBlackboard, uint32_t uiOffset) const |
| 125 | { |
| 126 | memcpy(pToBlackboard->_puiData, _puiData + uiOffset, pToBlackboard->_uiSize); |
| 127 | } |
| 128 | |
| 129 | // Serialization |
| 130 | void CParameterBlackboard::serialize(CBinaryStream& binaryStream) |
| 131 | { |
| 132 | if (binaryStream.isOut()) { |
| 133 | |
| 134 | binaryStream.write(_puiData, _uiSize); |
| 135 | } else { |
| 136 | |
| 137 | binaryStream.read(_puiData, _uiSize); |
| 138 | } |
| 139 | } |