datapoollocal update
This commit is contained in:
@ -3,56 +3,63 @@
|
||||
|
||||
#include <framework/datapool/PoolVariableIF.h>
|
||||
#include <framework/datapool/DataSetIF.h>
|
||||
#include <framework/housekeeping/HasHkPoolParametersIF.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
#include <framework/housekeeping/HousekeepingManager.h>
|
||||
|
||||
#include <map>
|
||||
/**
|
||||
* @brief This is the access class for non-array local data pool entries.
|
||||
*
|
||||
* @details
|
||||
*
|
||||
* @tparam T The template parameter sets the type of the variable.
|
||||
* Currently, all plain data types are supported, but in principle
|
||||
* any type is possible.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Local Pool Variable class which is used to access the local pools.
|
||||
* @details This class is not stored in the map. Instead, it is used to access
|
||||
* the pool entries by using a pointer to the map storing the pool
|
||||
* entries. It can also be used to organize these pool entries
|
||||
* into data sets.
|
||||
* @tparam T
|
||||
* @details
|
||||
* This class is not stored in the map. Instead, it is used to access
|
||||
* the pool entries by using a pointer to the map storing the pool
|
||||
* entries. It can also be used to organize these pool entries into data sets.
|
||||
*
|
||||
* @tparam T The template parameter sets the type of the variable. Currently,
|
||||
* all plain data types are supported, but in principle any type is possible.
|
||||
* @ingroup data_pool
|
||||
*/
|
||||
template<typename T>
|
||||
class LocalPoolVar: public PoolVariableIF, HasReturnvaluesIF {
|
||||
public:
|
||||
static constexpr lp_id_t INVALID_POOL_ID = 0xFFFFFFFF;
|
||||
//! Default ctor is forbidden.
|
||||
LocalPoolVar() = delete;
|
||||
|
||||
/**
|
||||
* This constructor is used by the data creators to have pool variable
|
||||
* instances which can also be stored in datasets.
|
||||
* @param set_id
|
||||
* @param setReadWriteMode
|
||||
* @param localPoolMap
|
||||
* @param dataSet
|
||||
* It does not fetch the current value from the data pool. This is performed
|
||||
* by the read() operation (which is not thread-safe).
|
||||
* Datasets can be used to access local pool entires in a thread-safe way.
|
||||
* @param poolId ID of the local pool entry.
|
||||
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||
* class itself which passes "this".
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
* @param dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
*/
|
||||
LocalPoolVar(lp_id_t poolId, HasHkPoolParametersIF* hkOwner,
|
||||
pool_rwm_t setReadWriteMode, DataSetIF* dataSet = nullptr);
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
|
||||
DataSetIF* dataSet = nullptr);
|
||||
|
||||
/**
|
||||
* This constructor is used by data users like controllers to have
|
||||
* access to the local pool variables of data creators by supplying
|
||||
* the respective creator object ID.
|
||||
* @param poolId
|
||||
* @param poolOwner
|
||||
* @param setReadWriteMode
|
||||
* @param dataSet
|
||||
* It does not fetch the current value from the data pool. This is performed
|
||||
* by the read() operation (which is not thread-safe).
|
||||
* Datasets can be used to access local pool entires in a thread-safe way.
|
||||
* @param poolId ID of the local pool entry.
|
||||
* @param hkOwner Pointer of the owner. This will generally be the calling
|
||||
* class itself which passes "this".
|
||||
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
||||
* @param dataSet The data set in which the variable shall register itself.
|
||||
* If nullptr, the variable is not registered.
|
||||
*/
|
||||
LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
|
||||
pool_rwm_t setReadWriteMode, DataSetIF* dataSet = nullptr);
|
||||
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
|
||||
DataSetIF* dataSet = nullptr);
|
||||
|
||||
virtual~ LocalPoolVar() {};
|
||||
|
||||
@ -63,33 +70,91 @@ public:
|
||||
*/
|
||||
T value = 0;
|
||||
|
||||
ReturnValue_t commit() override;
|
||||
ReturnValue_t read() override;
|
||||
pool_rwm_t getReadWriteMode() const override;
|
||||
uint32_t getDataPoolId() const override;
|
||||
|
||||
lp_id_t getDataPoolId() const override;
|
||||
void setDataPoolId(lp_id_t poolId);
|
||||
|
||||
bool isValid() const override;
|
||||
void setValid(uint8_t validity) override;
|
||||
void setValid(bool validity) override;
|
||||
uint8_t getValid() const;
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
const size_t max_size, bool bigEndian) const override;
|
||||
const size_t max_size, bool bigEndian) const override;
|
||||
virtual size_t getSerializedSize() const override;
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
bool bigEndian) override;
|
||||
bool bigEndian) override;
|
||||
|
||||
/**
|
||||
* @brief This is a call to read the array's values
|
||||
* from the global data pool.
|
||||
* @details
|
||||
* When executed, this operation tries to fetch the pool entry with matching
|
||||
* data pool id from the data pool and copies all array values and the valid
|
||||
* information to its local attributes.
|
||||
* In case of a failure (wrong type, size or pool id not found), the
|
||||
* variable is set to zero and invalid.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*
|
||||
*/
|
||||
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
/**
|
||||
* @brief The commit call copies the array values back to the data pool.
|
||||
* @details
|
||||
* It checks type and size, as well as if the variable is writable. If so,
|
||||
* the value is copied and the local valid flag is written back as well.
|
||||
* The read call is protected with a lock.
|
||||
* It is recommended to use DataSets to read and commit multiple variables
|
||||
* at once to avoid the overhead of unnecessary lock und unlock operations.
|
||||
*/
|
||||
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
|
||||
protected:
|
||||
/**
|
||||
* @brief Like #read, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t readWithoutLock() override;
|
||||
/**
|
||||
* @brief Like #commit, but without a lock protection of the global pool.
|
||||
* @details
|
||||
* The operation does NOT provide any mutual exclusive protection by itself.
|
||||
* This can be used if the lock is handled externally to avoid the overhead
|
||||
* of consecutive lock und unlock operations.
|
||||
* Declared protected to discourage free public usage.
|
||||
*/
|
||||
ReturnValue_t commitWithoutLock() override;
|
||||
|
||||
// std::ostream is the type for object std::cout
|
||||
// friend std::ostream& operator<< (std::ostream &out,
|
||||
// const LocalPoolVar &var) {
|
||||
// out << static_cast<int>(value);
|
||||
// return out;
|
||||
// }
|
||||
|
||||
private:
|
||||
lp_id_t localPoolId = INVALID_POOL_ID;
|
||||
//! @brief Pool ID of pool entry inside the used local pool.
|
||||
lp_id_t localPoolId = PoolVariableIF::NO_PARAMETER;
|
||||
//! @brief Read-write mode of the pool variable
|
||||
pool_rwm_t readWriteMode = pool_rwm_t::VAR_READ_WRITE;
|
||||
//! @brief Specifies whether the entry is valid or invalid.
|
||||
bool valid = false;
|
||||
|
||||
bool objectValid = true;
|
||||
//! Pointer to the class which manages the HK pool.
|
||||
HousekeepingManager* hkManager;
|
||||
};
|
||||
|
||||
#include <framework/datapoollocal/LocalPoolVariable.tpp>
|
||||
template<class T>
|
||||
using lp_variable = LocalPoolVar<T>;
|
||||
|
||||
using lp_bool_t = LocalPoolVar<bool>;
|
||||
template<class T>
|
||||
using lp_var_t = LocalPoolVar<T>;
|
||||
|
||||
using lp_bool_t = LocalPoolVar<uint8_t>;
|
||||
using lp_uint8_t = LocalPoolVar<uint8_t>;
|
||||
using lp_uint16_t = LocalPoolVar<uint16_t>;
|
||||
using lp_uint32_t = LocalPoolVar<uint32_t>;
|
||||
|
Reference in New Issue
Block a user