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