2020-09-28 21:28:03 +02:00
|
|
|
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
|
|
|
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
|
|
|
|
|
2020-10-14 01:25:15 +02:00
|
|
|
#include "LocalPoolObjectBase.h"
|
2020-09-28 21:28:03 +02:00
|
|
|
#include "HasLocalDataPoolIF.h"
|
|
|
|
#include "LocalDataPoolManager.h"
|
2020-05-17 01:17:11 +02:00
|
|
|
|
2020-08-23 20:27:00 +02:00
|
|
|
#include "../datapool/PoolVariableIF.h"
|
|
|
|
#include "../datapool/DataSetIF.h"
|
|
|
|
#include "../objectmanager/ObjectManagerIF.h"
|
|
|
|
#include "../serialize/SerializeAdapter.h"
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-05 20:34:34 +02:00
|
|
|
* @brief Local Pool Variable class which is used to access the local pools.
|
2020-05-17 01:17:11 +02:00
|
|
|
* @details
|
2020-06-05 20:34:34 +02:00
|
|
|
* 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.
|
2020-05-17 01:17:11 +02:00
|
|
|
*
|
2020-06-05 20:34:34 +02:00
|
|
|
* @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
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
template<typename T>
|
2020-10-14 01:25:15 +02:00
|
|
|
class LocalPoolVar: public LocalPoolObjectBase {
|
2020-05-17 01:17:11 +02:00
|
|
|
public:
|
2020-06-05 20:34:34 +02:00
|
|
|
//! Default ctor is forbidden.
|
|
|
|
LocalPoolVar() = delete;
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor is used by the data creators to have pool variable
|
|
|
|
* instances which can also be stored in datasets.
|
2020-06-07 02:22:18 +02:00
|
|
|
*
|
|
|
|
* It does not fetch the current value from the data pool, which
|
|
|
|
* has to be done by calling the read() operation.
|
|
|
|
* Datasets can be used to access multiple local pool entries in an
|
|
|
|
* efficient way. A pointer to a dataset can be passed to register
|
|
|
|
* the pool variable in that dataset directly.
|
2020-06-05 20:34:34 +02:00
|
|
|
* @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 dataSet The data set in which the variable shall register itself.
|
|
|
|
* If nullptr, the variable is not registered.
|
2020-09-19 01:17:43 +02:00
|
|
|
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
2020-07-09 00:59:10 +02:00
|
|
|
LocalPoolVar(lp_id_t poolId, HasLocalDataPoolIF* hkOwner,
|
2020-09-19 01:17:43 +02:00
|
|
|
DataSetIF* dataSet = nullptr,
|
|
|
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2020-06-07 02:22:18 +02:00
|
|
|
*
|
|
|
|
* It does not fetch the current value from the data pool, which
|
|
|
|
* has to be done by calling the read() operation.
|
|
|
|
* Datasets can be used to access multiple local pool entries in an
|
|
|
|
* efficient way. A pointer to a dataset can be passed to register
|
|
|
|
* the pool variable in that dataset directly.
|
2020-06-05 20:34:34 +02:00
|
|
|
* @param poolId ID of the local pool entry.
|
2020-06-07 02:22:18 +02:00
|
|
|
* @param hkOwner object ID of the pool owner.
|
2020-06-05 20:34:34 +02:00
|
|
|
* @param dataSet The data set in which the variable shall register itself.
|
|
|
|
* If nullptr, the variable is not registered.
|
2020-09-19 01:17:43 +02:00
|
|
|
* @param setReadWriteMode Specify the read-write mode of the pool variable.
|
|
|
|
*
|
2020-05-17 01:17:11 +02:00
|
|
|
*/
|
|
|
|
LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
|
2020-09-19 01:17:43 +02:00
|
|
|
DataSetIF* dataSet = nullptr,
|
|
|
|
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
|
2020-05-17 01:17:11 +02:00
|
|
|
|
|
|
|
virtual~ LocalPoolVar() {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This is the local copy of the data pool entry.
|
|
|
|
* @details The user can work on this attribute
|
|
|
|
* just like he would on a simple local variable.
|
|
|
|
*/
|
|
|
|
T value = 0;
|
|
|
|
|
2020-07-01 14:17:55 +02:00
|
|
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
|
|
|
SerializeIF::Endianness streamEndianness) const override;
|
2020-05-17 01:17:11 +02:00
|
|
|
virtual size_t getSerializedSize() const override;
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
2020-07-01 14:17:55 +02:00
|
|
|
SerializeIF::Endianness streamEndianness) override;
|
2020-06-05 20:34:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
*/
|
2020-06-07 02:22:18 +02:00
|
|
|
ReturnValue_t read(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
|
2020-06-05 20:34:34 +02:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2020-06-07 02:22:18 +02:00
|
|
|
ReturnValue_t commit(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
|
|
|
|
|
2020-08-08 13:20:02 +02:00
|
|
|
|
|
|
|
LocalPoolVar<T> &operator=(T newValue);
|
2020-06-05 20:34:34 +02:00
|
|
|
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
|
2020-06-06 23:15:05 +02:00
|
|
|
template <typename U>
|
|
|
|
friend std::ostream& operator<< (std::ostream &out,
|
|
|
|
const LocalPoolVar<U> &var);
|
2020-06-05 20:34:34 +02:00
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2020-08-23 20:27:00 +02:00
|
|
|
#include "LocalPoolVariable.tpp"
|
2020-06-05 20:34:34 +02:00
|
|
|
|
2020-05-17 01:17:11 +02:00
|
|
|
template<class T>
|
2020-06-05 20:34:34 +02:00
|
|
|
using lp_var_t = LocalPoolVar<T>;
|
2020-05-17 01:17:11 +02:00
|
|
|
|
2020-06-05 20:34:34 +02:00
|
|
|
using lp_bool_t = LocalPoolVar<uint8_t>;
|
2020-05-17 01:17:11 +02:00
|
|
|
using lp_uint8_t = LocalPoolVar<uint8_t>;
|
|
|
|
using lp_uint16_t = LocalPoolVar<uint16_t>;
|
|
|
|
using lp_uint32_t = LocalPoolVar<uint32_t>;
|
|
|
|
using lp_uint64_t = LocalPoolVar<uint64_t>;
|
|
|
|
using lp_int8_t = LocalPoolVar<int8_t>;
|
|
|
|
using lp_int16_t = LocalPoolVar<int16_t>;
|
|
|
|
using lp_int32_t = LocalPoolVar<int32_t>;
|
|
|
|
using lp_int64_t = LocalPoolVar<int64_t>;
|
|
|
|
using lp_float_t = LocalPoolVar<float>;
|
|
|
|
using lp_double_t = LocalPoolVar<double>;
|
|
|
|
|
2020-08-08 13:20:02 +02:00
|
|
|
|
2020-09-28 21:28:03 +02:00
|
|
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ */
|