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