Home | History | Annotate | Download | only in parameter
      1 /*
      2  * Copyright (c) 2011-2014, Intel Corporation
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without modification,
      6  * are permitted provided that the following conditions are met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright notice, this
      9  * list of conditions and the following disclaimer.
     10  *
     11  * 2. Redistributions in binary form must reproduce the above copyright notice,
     12  * this list of conditions and the following disclaimer in the documentation and/or
     13  * other materials provided with the distribution.
     14  *
     15  * 3. Neither the name of the copyright holder nor the names of its contributors
     16  * may be used to endorse or promote products derived from this software without
     17  * specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
     23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 #pragma once
     31 
     32 #include "ConfigurableElementWithMapping.h"
     33 #include "TypeElement.h"
     34 
     35 #include <list>
     36 #include <string>
     37 
     38 class IMapper;
     39 class CParameterBlackboard;
     40 class CParameterAccessContext;
     41 
     42 class CInstanceConfigurableElement : public CConfigurableElementWithMapping
     43 {
     44 public:
     45     enum Type {
     46         EBitParameter,
     47         EBitParameterBlock,
     48         EParameter,
     49         EStringParameter,
     50         EParameterBlock,
     51         EComponent
     52     };
     53 
     54     CInstanceConfigurableElement(const std::string& strName, const CTypeElement* pTypeElement);
     55 
     56     // Instantiated type
     57     const CTypeElement* getTypeElement() const;
     58 
     59     virtual bool getMappingData(const std::string& strKey, const std::string*& pStrValue) const;
     60 
     61     /**
     62      * Returns the mapping data associated to the type element of the current
     63      * InstanceConfigurableElement, as a formatted std::string
     64      *
     65      * @return A std::string containing the formatted mapping
     66      */
     67     std::string getFormattedMapping() const;
     68 
     69     // From CElement
     70     virtual std::string getKind() const;
     71 
     72     // Syncer to/from HW
     73     void setSyncer(ISyncer* pSyncer);
     74     void unsetSyncer();
     75 
     76     // Type
     77     virtual Type getType() const = 0;
     78 
     79     // Mapping execution
     80     bool map(IMapper& mapper, std::string& strError);
     81 
     82     // Element properties
     83     virtual void showProperties(std::string& strResult) const;
     84 
     85     // Scalar or Array?
     86     bool isScalar() const;
     87 
     88     // Array Length
     89     uint32_t getArrayLength() const;
     90 
     91     /**
     92      * Get the list of all the ancestors that have a mapping.
     93      *
     94      * The mapping is represented as a std::string of all the mapping data (key:value) defined in the
     95      * context of the element.
     96      * In this class, the method is generic and calls its parent getListOfElementsWithMappings(...)
     97      * method.
     98      *
     99      * @param[in:out] configurableElementPath List of all the ConfigurableElements found
    100      * that have a mapping. Elements are added at the end of the list, so the root Element will be
    101      * the last one.
    102      */
    103     virtual void getListOfElementsWithMapping(std::list<const CConfigurableElement*>&
    104                                                configurableElementPath) const;
    105 
    106     virtual void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const;
    107 
    108 protected:
    109     // Syncer
    110     virtual ISyncer* getSyncer() const;
    111     // Syncer set (descendant)
    112     virtual void fillSyncerSetFromDescendant(CSyncerSet& syncerSet) const;
    113 
    114     /**
    115      * Performs the sync if the AutoSync is enabled.
    116      * If AutoSync is disabled, any call to sync will returns true, even if synchronization has not
    117      * been done. It will happen when the AutoSync will be switched back on.
    118      *
    119      * @param[in:out] parameterAccessContext Parameter access context object
    120      *
    121      * @return true if the synchronization succeded or if the AutoSync is off, false otherwise.
    122      */
    123     bool sync(CParameterAccessContext& parameterAccessContext) const;
    124 
    125     // Check parameter access path well formed for leaf elements
    126     static bool checkPathExhausted(CPathNavigator& pathNavigator, CErrorContext& errorContext);
    127 private:
    128     // Type Element
    129     const CTypeElement* _pTypeElement;
    130 
    131     // Sync to HW
    132     ISyncer* _pSyncer;
    133 };
    134 
    135