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 "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 | |
| 41 | CInstanceConfigurableElement::CInstanceConfigurableElement(const string& strName, const CTypeElement* pTypeElement) : base(strName), _pTypeElement(pTypeElement), _pSyncer(NULL) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | string CInstanceConfigurableElement::getKind() const |
| 46 | { |
| 47 | // Delegate |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 48 | return _pTypeElement->getKind(); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Type element |
| 52 | const CTypeElement* CInstanceConfigurableElement::getTypeElement() const |
| 53 | { |
| 54 | return _pTypeElement; |
| 55 | } |
| 56 | |
| 57 | // Mapping |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 58 | bool CInstanceConfigurableElement::getMappingData(const string& strKey, const string*& pStrValue) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 59 | { |
| 60 | // Delegate |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 61 | return getTypeElement()->getMappingData(strKey, pStrValue); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError) |
| 65 | { |
| 66 | bool bHasMappingData = getTypeElement()->hasMappingData(); |
| 67 | |
| 68 | // Begin |
| 69 | if (bHasMappingData) { |
| 70 | |
Patrick Benavoli | d3a86bf | 2011-11-07 19:33:30 +0100 | [diff] [blame] | 71 | bool bKeepDiving; |
| 72 | |
| 73 | if (!mapper.mapBegin(this, bKeepDiving, strError)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 74 | |
| 75 | return false; |
| 76 | } |
Patrick Benavoli | d3a86bf | 2011-11-07 19:33:30 +0100 | [diff] [blame] | 77 | // Go on through children? |
| 78 | if (!bKeepDiving) { |
| 79 | |
| 80 | return true; |
| 81 | } |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | // Map children |
| 85 | uint32_t uiNbChildren = getNbChildren(); |
| 86 | uint32_t uiChild; |
| 87 | |
| 88 | for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { |
| 89 | |
| 90 | CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); |
| 91 | |
| 92 | if (!pInstanceConfigurableChildElement->map(mapper, strError)) { |
| 93 | |
| 94 | return false; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // End |
| 99 | if (bHasMappingData) { |
| 100 | |
| 101 | mapper.mapEnd(); |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 106 | // Element properties |
| 107 | void CInstanceConfigurableElement::showProperties(string& strResult) const |
| 108 | { |
| 109 | base::showProperties(strResult); |
| 110 | |
| 111 | // Delegate to type element |
| 112 | _pTypeElement->showProperties(strResult); |
| 113 | } |
| 114 | |
Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 115 | // Scalar or Array? |
| 116 | bool CInstanceConfigurableElement::isScalar() const |
| 117 | { |
| 118 | return _pTypeElement->isScalar(); |
| 119 | } |
| 120 | |
| 121 | // Array Length |
| 122 | uint32_t CInstanceConfigurableElement::getArrayLength() const |
| 123 | { |
| 124 | return _pTypeElement->getArrayLength(); |
| 125 | } |
| 126 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 127 | // Sync to HW |
| 128 | void CInstanceConfigurableElement::setSyncer(ISyncer* pSyncer) |
| 129 | { |
| 130 | assert(!_pSyncer); |
| 131 | |
| 132 | _pSyncer = pSyncer; |
| 133 | } |
| 134 | |
| 135 | void CInstanceConfigurableElement::unsetSyncer() |
| 136 | { |
| 137 | _pSyncer = NULL; |
| 138 | } |
| 139 | |
| 140 | // Syncer |
| 141 | ISyncer* CInstanceConfigurableElement::getSyncer() const |
| 142 | { |
| 143 | if (_pSyncer) { |
| 144 | |
| 145 | return _pSyncer; |
| 146 | } |
| 147 | // Check parent |
| 148 | return base::getSyncer(); |
| 149 | } |
| 150 | |
| 151 | // Syncer set (descendant) |
| 152 | void CInstanceConfigurableElement::fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const |
| 153 | { |
| 154 | if (_pSyncer) { |
| 155 | |
| 156 | syncerSet += _pSyncer; |
| 157 | } else { |
| 158 | // Continue digging |
| 159 | base::fillSyncerSetFromDescendant(syncerSet); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // Sync |
| 164 | bool CInstanceConfigurableElement::sync(CParameterAccessContext& parameterAccessContext) const |
| 165 | { |
| 166 | ISyncer* pSyncer = getSyncer(); |
| 167 | |
| 168 | if (!pSyncer) { |
| 169 | |
Patrick Benavoli | 1352ae5 | 2011-10-21 16:48:04 +0200 | [diff] [blame] | 170 | parameterAccessContext.setError("Unable to synchronize modification. No Syncer object associated to configurable element:"); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 171 | |
| 172 | return false; |
| 173 | } |
| 174 | string strError; |
| 175 | |
| 176 | if (!pSyncer->sync(*parameterAccessContext.getParameterBlackboard(), false, strError)) { |
| 177 | |
| 178 | parameterAccessContext.setError(strError); |
| 179 | |
| 180 | return false; |
| 181 | } |
| 182 | return true; |
| 183 | } |
| 184 | |
| 185 | // Check parameter access path well formed for leaf elements |
| 186 | bool CInstanceConfigurableElement::checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext) |
| 187 | { |
| 188 | string* pStrChildName = pathNavigator.next(); |
| 189 | |
| 190 | if (pStrChildName) { |
| 191 | |
| 192 | // Should be leaf element |
| 193 | errorContext.setError("Path not found: " + pathNavigator.getCurrentPath()); |
| 194 | |
| 195 | return false; |
| 196 | } |
| 197 | return true; |
| 198 | } |
| 199 | |