Home | History | Annotate | Download | only in parameter
      1 /*
      2  * Copyright (c) 2011-2015, 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 "parameter_export.h"
     33 
     34 #include "Syncer.h"
     35 #include <log/Logger.h>
     36 
     37 #include <stdint.h>
     38 #include <string>
     39 
     40 class CInstanceConfigurableElement;
     41 class CMappingContext;
     42 class CSubsystem;
     43 
     44 class PARAMETER_EXPORT CSubsystemObject : private ISyncer
     45 {
     46 public:
     47     CSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement,
     48                      core::log::Logger &logger);
     49     virtual ~CSubsystemObject();
     50 
     51     /**
     52      * Return the mapping value of the SubystemObject.
     53      *
     54      * @return A std::string containing the mapping value
     55      */
     56     virtual std::string getFormattedMappingValue() const;
     57 
     58     // Configurable element retrieval
     59     const CInstanceConfigurableElement *getConfigurableElement() const;
     60 
     61 protected:
     62     /** FIXME: plugins should not have direct access to blackboard memory.
     63      *         Ie: This method should be removed or return a abstracted iterator.
     64      */
     65     uint8_t *getBlackboardLocation() const;
     66     // Size
     67     size_t getSize() const;
     68 
     69     /**
     70      * Conversion of int8, int16, int32 to int (taking care of sign extension)
     71      *
     72      * @param[in] instanceConfigurableElement pointer to configurable element instance
     73      * @param[in] sizeOptimizedData data to convert
     74      *
     75      * @return the data converted to int
     76      */
     77     int toPlainInteger(const CInstanceConfigurableElement *instanceConfigurableElement,
     78                        int sizeOptimizedData);
     79 
     80     // Sync to/from HW
     81     virtual bool sendToHW(std::string &strError);
     82     virtual bool receiveFromHW(std::string &strError);
     83     // Fall back HW access
     84     virtual bool accessHW(bool bReceive, std::string &strError);
     85     // Blackboard access from subsystems
     86     void blackboardRead(void *pvData, size_t size);
     87     void blackboardWrite(const void *pvData, size_t size);
     88     // Belonging Subsystem retrieval
     89     const CSubsystem *getSubsystem() const;
     90 
     91     /** Logging methods
     92      *@{
     93      */
     94     core::log::details::Info info() const { return _logger.info(); }
     95     core::log::details::Warning warning() const { return _logger.warning(); }
     96     /* @} */
     97 
     98 private:
     99     // from ISyncer
    100     /** This method is not supposed to be overridden by plugins
    101      *  as if not called, plugins will not work (sets _blackboard).
    102      */
    103     bool sync(CParameterBlackboard &parameterBlackboard, bool bBack,
    104               std::string &strError) override final;
    105 
    106     // Default back synchronization
    107     void setDefaultValues(CParameterBlackboard &parameterBlackboard) const;
    108 
    109     /** @return the offset in the main blackboard of the sync values. */
    110     size_t getOffset() const;
    111 
    112     // Prevent unsupported operators
    113     CSubsystemObject(const CSubsystemObject &);
    114 
    115     // Define affection operator
    116     const CSubsystemObject &operator=(const CSubsystemObject &);
    117 
    118     /** Application Logger */
    119     core::log::Logger &_logger;
    120 
    121     // Instance element to sync from/to
    122     CInstanceConfigurableElement *_pInstanceConfigurableElement;
    123     // Data size
    124     size_t _dataSize;
    125     // Blackboard data location
    126     CParameterBlackboard *_blackboard{nullptr};
    127     // Accessed index for Subsystem read/write from/to blackboard
    128     size_t _accessedIndex{0};
    129 };
    130