1*c33452fbSAndroid Build Coastguard Worker /* 2*c33452fbSAndroid Build Coastguard Worker * Copyright (c) 2011-2015, Intel Corporation 3*c33452fbSAndroid Build Coastguard Worker * All rights reserved. 4*c33452fbSAndroid Build Coastguard Worker * 5*c33452fbSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without modification, 6*c33452fbSAndroid Build Coastguard Worker * are permitted provided that the following conditions are met: 7*c33452fbSAndroid Build Coastguard Worker * 8*c33452fbSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright notice, this 9*c33452fbSAndroid Build Coastguard Worker * list of conditions and the following disclaimer. 10*c33452fbSAndroid Build Coastguard Worker * 11*c33452fbSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright notice, 12*c33452fbSAndroid Build Coastguard Worker * this list of conditions and the following disclaimer in the documentation and/or 13*c33452fbSAndroid Build Coastguard Worker * other materials provided with the distribution. 14*c33452fbSAndroid Build Coastguard Worker * 15*c33452fbSAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the names of its contributors 16*c33452fbSAndroid Build Coastguard Worker * may be used to endorse or promote products derived from this software without 17*c33452fbSAndroid Build Coastguard Worker * specific prior written permission. 18*c33452fbSAndroid Build Coastguard Worker * 19*c33452fbSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20*c33452fbSAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21*c33452fbSAndroid Build Coastguard Worker * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22*c33452fbSAndroid Build Coastguard Worker * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23*c33452fbSAndroid Build Coastguard Worker * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24*c33452fbSAndroid Build Coastguard Worker * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25*c33452fbSAndroid Build Coastguard Worker * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26*c33452fbSAndroid Build Coastguard Worker * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27*c33452fbSAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28*c33452fbSAndroid Build Coastguard Worker * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*c33452fbSAndroid Build Coastguard Worker */ 30*c33452fbSAndroid Build Coastguard Worker #pragma once 31*c33452fbSAndroid Build Coastguard Worker 32*c33452fbSAndroid Build Coastguard Worker #include "parameter_export.h" 33*c33452fbSAndroid Build Coastguard Worker 34*c33452fbSAndroid Build Coastguard Worker #include "Element.h" 35*c33452fbSAndroid Build Coastguard Worker 36*c33452fbSAndroid Build Coastguard Worker #include <list> 37*c33452fbSAndroid Build Coastguard Worker #include <vector> 38*c33452fbSAndroid Build Coastguard Worker 39*c33452fbSAndroid Build Coastguard Worker class CConfigurableDomain; 40*c33452fbSAndroid Build Coastguard Worker class CSyncerSet; 41*c33452fbSAndroid Build Coastguard Worker class ISyncer; 42*c33452fbSAndroid Build Coastguard Worker class CSubsystem; 43*c33452fbSAndroid Build Coastguard Worker class CConfigurationAccessContext; 44*c33452fbSAndroid Build Coastguard Worker class CParameterAccessContext; 45*c33452fbSAndroid Build Coastguard Worker class CAreaConfiguration; 46*c33452fbSAndroid Build Coastguard Worker 47*c33452fbSAndroid Build Coastguard Worker class PARAMETER_EXPORT CConfigurableElement : public CElement 48*c33452fbSAndroid Build Coastguard Worker { 49*c33452fbSAndroid Build Coastguard Worker friend class CConfigurableDomain; 50*c33452fbSAndroid Build Coastguard Worker friend class CDomainConfiguration; 51*c33452fbSAndroid Build Coastguard Worker typedef std::list<const CConfigurableDomain *>::const_iterator 52*c33452fbSAndroid Build Coastguard Worker ConfigurableDomainListConstIterator; 53*c33452fbSAndroid Build Coastguard Worker 54*c33452fbSAndroid Build Coastguard Worker public: 55*c33452fbSAndroid Build Coastguard Worker CConfigurableElement(const std::string &strName = ""); 56*c33452fbSAndroid Build Coastguard Worker ~CConfigurableElement() override = default; 57*c33452fbSAndroid Build Coastguard Worker 58*c33452fbSAndroid Build Coastguard Worker // Offset in main blackboard 59*c33452fbSAndroid Build Coastguard Worker void setOffset(size_t offset); 60*c33452fbSAndroid Build Coastguard Worker size_t getOffset() const; 61*c33452fbSAndroid Build Coastguard Worker 62*c33452fbSAndroid Build Coastguard Worker // Allocation 63*c33452fbSAndroid Build Coastguard Worker virtual size_t getFootPrint() const; 64*c33452fbSAndroid Build Coastguard Worker 65*c33452fbSAndroid Build Coastguard Worker // Syncer set (me, ascendant or descendant ones) 66*c33452fbSAndroid Build Coastguard Worker void fillSyncerSet(CSyncerSet &syncerSet) const; 67*c33452fbSAndroid Build Coastguard Worker 68*c33452fbSAndroid Build Coastguard Worker // Belonging domain 69*c33452fbSAndroid Build Coastguard Worker bool belongsTo(const CConfigurableDomain *pConfigurableDomain) const; 70*c33452fbSAndroid Build Coastguard Worker 71*c33452fbSAndroid Build Coastguard Worker // Belonging domains 72*c33452fbSAndroid Build Coastguard Worker void listBelongingDomains(std::string &strResult, bool bVertical = true) const; 73*c33452fbSAndroid Build Coastguard Worker 74*c33452fbSAndroid Build Coastguard Worker // Matching check for domain association 75*c33452fbSAndroid Build Coastguard Worker bool hasNoDomainAssociated() const; 76*c33452fbSAndroid Build Coastguard Worker 77*c33452fbSAndroid Build Coastguard Worker // Matching check for no valid associated domains 78*c33452fbSAndroid Build Coastguard Worker bool hasNoValidDomainAssociated() const; 79*c33452fbSAndroid Build Coastguard Worker 80*c33452fbSAndroid Build Coastguard Worker // Owning domains 81*c33452fbSAndroid Build Coastguard Worker void listAssociatedDomains(std::string &strResult, bool bVertical = true) const; 82*c33452fbSAndroid Build Coastguard Worker size_t getBelongingDomainCount() const; 83*c33452fbSAndroid Build Coastguard Worker 84*c33452fbSAndroid Build Coastguard Worker // Elements with no domains 85*c33452fbSAndroid Build Coastguard Worker void listRogueElements(std::string &strResult) const; 86*c33452fbSAndroid Build Coastguard Worker 87*c33452fbSAndroid Build Coastguard Worker /** @return true if element is rogue, false otherwise 88*c33452fbSAndroid Build Coastguard Worker * 89*c33452fbSAndroid Build Coastguard Worker * An element is rogue if it is disjoint with all domains. 90*c33452fbSAndroid Build Coastguard Worker * 91*c33452fbSAndroid Build Coastguard Worker * Ie: An element is rogue if neither its descendants, ascendants 92*c33452fbSAndroid Build Coastguard Worker * nor itself are associated with any domain. 93*c33452fbSAndroid Build Coastguard Worker * 94*c33452fbSAndroid Build Coastguard Worker * Ie: An element is *not* rogue if any of its descendants, ascendants 95*c33452fbSAndroid Build Coastguard Worker * or itself are associated with at least one domain. 96*c33452fbSAndroid Build Coastguard Worker */ 97*c33452fbSAndroid Build Coastguard Worker bool isRogue() const; 98*c33452fbSAndroid Build Coastguard Worker 99*c33452fbSAndroid Build Coastguard Worker // Footprint as string 100*c33452fbSAndroid Build Coastguard Worker std::string getFootprintAsString() const; 101*c33452fbSAndroid Build Coastguard Worker 102*c33452fbSAndroid Build Coastguard Worker // Belonging subsystem 103*c33452fbSAndroid Build Coastguard Worker virtual const CSubsystem *getBelongingSubsystem() const; 104*c33452fbSAndroid Build Coastguard Worker 105*c33452fbSAndroid Build Coastguard Worker // Check element is a parameter 106*c33452fbSAndroid Build Coastguard Worker virtual bool isParameter() const; 107*c33452fbSAndroid Build Coastguard Worker 108*c33452fbSAndroid Build Coastguard Worker // AreaConfiguration creation 109*c33452fbSAndroid Build Coastguard Worker virtual CAreaConfiguration *createAreaConfiguration(const CSyncerSet *pSyncerSet) const; 110*c33452fbSAndroid Build Coastguard Worker 111*c33452fbSAndroid Build Coastguard Worker // Parameter access 112*c33452fbSAndroid Build Coastguard Worker virtual bool accessValue(CPathNavigator &pathNavigator, std::string &strValue, bool bSet, 113*c33452fbSAndroid Build Coastguard Worker CParameterAccessContext ¶meterAccessContext) const; 114*c33452fbSAndroid Build Coastguard Worker 115*c33452fbSAndroid Build Coastguard Worker /** Gets the element as an array of bytes. 116*c33452fbSAndroid Build Coastguard Worker * 117*c33452fbSAndroid Build Coastguard Worker * This is like having a direct access to the blackboard. 118*c33452fbSAndroid Build Coastguard Worker * 119*c33452fbSAndroid Build Coastguard Worker * @param[out] bytes Where to store the result. 120*c33452fbSAndroid Build Coastguard Worker * @param[in] parameterAccessContext Context containing the blackboard to 121*c33452fbSAndroid Build Coastguard Worker * read from. 122*c33452fbSAndroid Build Coastguard Worker */ 123*c33452fbSAndroid Build Coastguard Worker void getSettingsAsBytes(std::vector<uint8_t> &bytes, 124*c33452fbSAndroid Build Coastguard Worker CParameterAccessContext ¶meterAccessContext) const; 125*c33452fbSAndroid Build Coastguard Worker /** Sets the element as if it was an array of bytes. 126*c33452fbSAndroid Build Coastguard Worker * 127*c33452fbSAndroid Build Coastguard Worker * This is like having a direct access to the blackboard. 128*c33452fbSAndroid Build Coastguard Worker * 129*c33452fbSAndroid Build Coastguard Worker * @param[out] bytes The content to be set. 130*c33452fbSAndroid Build Coastguard Worker * @param[in] parameterAccessContext Context containing the blackboard to 131*c33452fbSAndroid Build Coastguard Worker * write to. 132*c33452fbSAndroid Build Coastguard Worker */ 133*c33452fbSAndroid Build Coastguard Worker bool setSettingsAsBytes(const std::vector<uint8_t> &bytes, 134*c33452fbSAndroid Build Coastguard Worker CParameterAccessContext ¶meterAccessContext) const; 135*c33452fbSAndroid Build Coastguard Worker 136*c33452fbSAndroid Build Coastguard Worker /** @return List of all ConfigurableElements that have a mapping relevant in this context. 137*c33452fbSAndroid Build Coastguard Worker * Ie: return self and CConfigurableElement ancestor of this node. 138*c33452fbSAndroid Build Coastguard Worker * 139*c33452fbSAndroid Build Coastguard Worker */ 140*c33452fbSAndroid Build Coastguard Worker std::list<const CConfigurableElement *> getConfigurableElementContext() const; 141*c33452fbSAndroid Build Coastguard Worker 142*c33452fbSAndroid Build Coastguard Worker // Used for simulation and virtual subsystems 143*c33452fbSAndroid Build Coastguard Worker virtual void setDefaultValues(CParameterAccessContext ¶meterAccessContext) const; 144*c33452fbSAndroid Build Coastguard Worker 145*c33452fbSAndroid Build Coastguard Worker // Element properties 146*c33452fbSAndroid Build Coastguard Worker void showProperties(std::string &strResult) const override; 147*c33452fbSAndroid Build Coastguard Worker 148*c33452fbSAndroid Build Coastguard Worker /** 149*c33452fbSAndroid Build Coastguard Worker * Get the value associated to a mapping key in the object's mapping 150*c33452fbSAndroid Build Coastguard Worker * 151*c33452fbSAndroid Build Coastguard Worker * @param[in] strKey the mapping key 152*c33452fbSAndroid Build Coastguard Worker * @param[out] pStrValue the associated value 153*c33452fbSAndroid Build Coastguard Worker * 154*c33452fbSAndroid Build Coastguard Worker * @return true if @p strKey is found in the object's mapping, false if not 155*c33452fbSAndroid Build Coastguard Worker */ 156*c33452fbSAndroid Build Coastguard Worker virtual bool getMappingData(const std::string &strKey, const std::string *&pStrValue) const = 0; 157*c33452fbSAndroid Build Coastguard Worker /** Get the string representation of the mapping 158*c33452fbSAndroid Build Coastguard Worker * 159*c33452fbSAndroid Build Coastguard Worker * If applicable, amend values are applied to the leaf element. 160*c33452fbSAndroid Build Coastguard Worker */ 161*c33452fbSAndroid Build Coastguard Worker virtual std::string getFormattedMapping() const = 0; 162*c33452fbSAndroid Build Coastguard Worker 163*c33452fbSAndroid Build Coastguard Worker // XML configuration settings parsing 164*c33452fbSAndroid Build Coastguard Worker virtual bool serializeXmlSettings( 165*c33452fbSAndroid Build Coastguard Worker CXmlElement &xmlConfigurationSettingsElementContent, 166*c33452fbSAndroid Build Coastguard Worker CConfigurationAccessContext &configurationAccessContext) const; 167*c33452fbSAndroid Build Coastguard Worker 168*c33452fbSAndroid Build Coastguard Worker bool fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) final; 169*c33452fbSAndroid Build Coastguard Worker 170*c33452fbSAndroid Build Coastguard Worker void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const final; 171*c33452fbSAndroid Build Coastguard Worker 172*c33452fbSAndroid Build Coastguard Worker /** Deserialize the structure from xml. */ structureFromXml(const CXmlElement & xmlElement,CXmlSerializingContext & serializingContext)173*c33452fbSAndroid Build Coastguard Worker virtual bool structureFromXml(const CXmlElement &xmlElement, 174*c33452fbSAndroid Build Coastguard Worker CXmlSerializingContext &serializingContext) 175*c33452fbSAndroid Build Coastguard Worker { 176*c33452fbSAndroid Build Coastguard Worker // Forward to Element::fromXml. 177*c33452fbSAndroid Build Coastguard Worker // This is unfortunate as Element::fromXml will call back 178*c33452fbSAndroid Build Coastguard Worker // fromXml on each children. 179*c33452fbSAndroid Build Coastguard Worker // Thus on each non leaf node of the tree, the code will test if 180*c33452fbSAndroid Build Coastguard Worker // the setting or the structure are to be serialized. 181*c33452fbSAndroid Build Coastguard Worker // This test could be avoided by several ways including: 182*c33452fbSAndroid Build Coastguard Worker // - split 2 roles fromXml in two function 183*c33452fbSAndroid Build Coastguard Worker // 1) construct the elements 184*c33452fbSAndroid Build Coastguard Worker // 2) recursive call on children 185*c33452fbSAndroid Build Coastguard Worker // - dispatch in with a virtual method. This would not not remove 186*c33452fbSAndroid Build Coastguard Worker // the branching rather hide it behind a virtual method override. 187*c33452fbSAndroid Build Coastguard Worker return CElement::fromXml(xmlElement, serializingContext); 188*c33452fbSAndroid Build Coastguard Worker } 189*c33452fbSAndroid Build Coastguard Worker 190*c33452fbSAndroid Build Coastguard Worker /** Serialize the structure to xml. */ structureToXml(CXmlElement & xmlElement,CXmlSerializingContext & serializingContext)191*c33452fbSAndroid Build Coastguard Worker virtual void structureToXml(CXmlElement &xmlElement, 192*c33452fbSAndroid Build Coastguard Worker CXmlSerializingContext &serializingContext) const 193*c33452fbSAndroid Build Coastguard Worker { 194*c33452fbSAndroid Build Coastguard Worker // See structureFromXml implementation comment. 195*c33452fbSAndroid Build Coastguard Worker CElement::toXml(xmlElement, serializingContext); 196*c33452fbSAndroid Build Coastguard Worker } 197*c33452fbSAndroid Build Coastguard Worker 198*c33452fbSAndroid Build Coastguard Worker protected: 199*c33452fbSAndroid Build Coastguard Worker // Syncer (me or ascendant) 200*c33452fbSAndroid Build Coastguard Worker virtual ISyncer *getSyncer() const; 201*c33452fbSAndroid Build Coastguard Worker // Syncer set (descendant) 202*c33452fbSAndroid Build Coastguard Worker virtual void fillSyncerSetFromDescendant(CSyncerSet &syncerSet) const; 203*c33452fbSAndroid Build Coastguard Worker // Configuration Domain local search 204*c33452fbSAndroid Build Coastguard Worker bool containsConfigurableDomain(const CConfigurableDomain *pConfigurableDomain) const; 205*c33452fbSAndroid Build Coastguard Worker 206*c33452fbSAndroid Build Coastguard Worker private: 207*c33452fbSAndroid Build Coastguard Worker // Content dumping. Override and stop further deriving: Configurable 208*c33452fbSAndroid Build Coastguard Worker // Elements should be called with the overloaded version taking a 209*c33452fbSAndroid Build Coastguard Worker // "Parameter Access Context" (The name is misleading as it is actually 210*c33452fbSAndroid Build Coastguard Worker // used to access any Configurable Element). 211*c33452fbSAndroid Build Coastguard Worker std::string logValue(utility::ErrorContext &errorContext) const final; 212*c33452fbSAndroid Build Coastguard Worker virtual std::string logValue(CParameterAccessContext &context) const; 213*c33452fbSAndroid Build Coastguard Worker 214*c33452fbSAndroid Build Coastguard Worker // Configurable domain association 215*c33452fbSAndroid Build Coastguard Worker void addAttachedConfigurableDomain(const CConfigurableDomain *pConfigurableDomain); 216*c33452fbSAndroid Build Coastguard Worker void removeAttachedConfigurableDomain(const CConfigurableDomain *pConfigurableDomain); 217*c33452fbSAndroid Build Coastguard Worker 218*c33452fbSAndroid Build Coastguard Worker // Belonging domain ascending search 219*c33452fbSAndroid Build Coastguard Worker bool belongsToDomainAscending(const CConfigurableDomain *pConfigurableDomain) const; 220*c33452fbSAndroid Build Coastguard Worker 221*c33452fbSAndroid Build Coastguard Worker // Belonging domains 222*c33452fbSAndroid Build Coastguard Worker void getBelongingDomains(std::list<const CConfigurableDomain *> &configurableDomainList) const; 223*c33452fbSAndroid Build Coastguard Worker void listDomains(const std::list<const CConfigurableDomain *> &configurableDomainList, 224*c33452fbSAndroid Build Coastguard Worker std::string &strResult, bool bVertical) const; 225*c33452fbSAndroid Build Coastguard Worker 226*c33452fbSAndroid Build Coastguard Worker // Check parent is still of current type (by structure knowledge) 227*c33452fbSAndroid Build Coastguard Worker bool isOfConfigurableElementType(const CElement *pParent) const; 228*c33452fbSAndroid Build Coastguard Worker 229*c33452fbSAndroid Build Coastguard Worker // Offset in main blackboard 230*c33452fbSAndroid Build Coastguard Worker size_t _offset{0}; 231*c33452fbSAndroid Build Coastguard Worker 232*c33452fbSAndroid Build Coastguard Worker // Associated configurable domains 233*c33452fbSAndroid Build Coastguard Worker std::list<const CConfigurableDomain *> _configurableDomainList; 234*c33452fbSAndroid Build Coastguard Worker }; 235