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 "Parameter.h" |
| 32 | #include "ParameterType.h" |
| 33 | #include "ParameterAccessContext.h" |
| 34 | #include "ConfigurationAccessContext.h" |
| 35 | #include "ParameterBlackboard.h" |
| 36 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 37 | #define base CBaseParameter |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 38 | |
| 39 | CParameter::CParameter(const string& strName, const CTypeElement* pTypeElement) : base(strName, pTypeElement) |
| 40 | { |
| 41 | } |
| 42 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 43 | CInstanceConfigurableElement::Type CParameter::getType() const |
| 44 | { |
| 45 | return EParameter; |
| 46 | } |
| 47 | |
| 48 | // XML configuration settings parsing/composing |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 49 | bool CParameter::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 50 | { |
| 51 | // Check for value space |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 52 | handleValueSpaceAttribute(xmlConfigurationSettingsElementContent, configurationAccessContext); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 53 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 54 | // Base |
| 55 | return base::serializeXmlSettings(xmlConfigurationSettingsElementContent, configurationAccessContext); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 58 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 59 | // Value space handling for configuration import |
| 60 | void CParameter::handleValueSpaceAttribute(CXmlElement& xmlConfigurableElementSettingsElement, CConfigurationAccessContext& configurationAccessContext) const |
| 61 | { |
| 62 | // Delegate to type |
| 63 | static_cast<const CParameterType*>(getTypeElement())->handleValueSpaceAttribute(xmlConfigurableElementSettingsElement, configurationAccessContext); |
| 64 | } |
| 65 | |
| 66 | uint32_t CParameter::getFootPrint() const |
| 67 | { |
| 68 | return getSize(); |
| 69 | } |
| 70 | |
| 71 | uint32_t CParameter::getSize() const |
| 72 | { |
| 73 | return static_cast<const CParameterType*>(getTypeElement())->getSize(); |
| 74 | } |
| 75 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 76 | // Used for simulation only |
| 77 | void CParameter::setDefaultValues(CParameterAccessContext& parameterAccessContext) const |
| 78 | { |
| 79 | // Get default value from type |
| 80 | uint32_t uiDefaultValue = static_cast<const CParameterType*>(getTypeElement())->getDefaultValue(); |
| 81 | |
| 82 | // Write blackboard |
| 83 | CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 84 | |
| 85 | // Beware this code works on little endian architectures only! |
| 86 | pBlackboard->write(&uiDefaultValue, getSize(), getOffset(), parameterAccessContext.isBigEndianSubsystem()); |
| 87 | } |
| 88 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame^] | 89 | // Actual parameter access |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 90 | bool CParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 91 | { |
| 92 | uint32_t uiData; |
| 93 | |
| 94 | if (!static_cast<const CParameterType*>(getTypeElement())->asInteger(strValue, uiData, parameterAccessContext)) { |
| 95 | |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | // Write blackboard |
| 100 | CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 101 | |
| 102 | // Beware this code works on little endian architectures only! |
| 103 | pBlackboard->write(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | void CParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 109 | { |
| 110 | uint32_t uiData = 0; |
| 111 | |
| 112 | // Read blackboard |
| 113 | CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 114 | |
| 115 | // Beware this code works on little endian architectures only! |
| 116 | pBlackboard->read(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| 117 | |
| 118 | static_cast<const CParameterType*>(getTypeElement())->asString(uiData, strValue, parameterAccessContext); |
| 119 | } |
| 120 | |