201 lines
7.6 KiB
C++
201 lines
7.6 KiB
C++
#pragma once
|
|
|
|
#include "SharedPool.h"
|
|
#include "definitions.h"
|
|
#include "fsfw/datapool/DataSetIF.h"
|
|
#include "fsfw/datapool/PoolDataSetBase.h"
|
|
|
|
class PeriodicHkGenerationHelper;
|
|
class PeriodicHkGenerationIF;
|
|
class PeriodicHousekeepingHelper;
|
|
|
|
namespace datapool {
|
|
|
|
/**
|
|
* @brief The LocalDataSet class manages a set of locally checked out
|
|
* variables for local data pools
|
|
* @details
|
|
* Extends the PoolDataSetBase class for local data pools by introducing
|
|
* a validity state, a flag to mark the set as changed, and various other
|
|
* functions to make it usable by the LocalDataPoolManager class.
|
|
*
|
|
* This class manages a list, where a set of local variables (or pool variables)
|
|
* are registered. They are checked-out (i.e. their values are looked
|
|
* up and copied) with the read call. After the user finishes working with the
|
|
* pool variables, he can write back all variable values to the pool with
|
|
* the commit call. The data set manages locking and freeing the local data
|
|
* pools, to ensure thread-safety.
|
|
*
|
|
* Pool variables can be added to the dataset by using the constructor
|
|
* argument of the pool variable or using the #registerVariable member function.
|
|
*
|
|
* An internal state manages usage of this class. Variables may only be
|
|
* registered before any read call is made, and the commit call can only happen
|
|
* after the read call.
|
|
*
|
|
* If pool variables are writable and not committed until destruction
|
|
* of the set, the DataSet class automatically sets the valid flag in the
|
|
* data pool to invalid (without) changing the variable's value.
|
|
*
|
|
* @ingroup data_pool
|
|
*/
|
|
class SharedSetBase : public SerializeIF, public PoolDataSetIF {
|
|
// friend class PeriodicHousekeepingHelper;
|
|
|
|
public:
|
|
/**
|
|
* @brief Constructor for the creator of local pool data.
|
|
* @details
|
|
* This constructor also initializes the components required for
|
|
* periodic handling.
|
|
*/
|
|
SharedSetBase(SharedPool& sharedPool, uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
|
size_t maxNumberOfVariables);
|
|
|
|
/**
|
|
* @brief Constructor for users of the local pool data, which need
|
|
* to access data created by one HK manager.
|
|
* @details
|
|
* Unlike the first constructor, no component for periodic handling
|
|
* will be initiated.
|
|
* @param sid Unique identifier of dataset consisting of object ID and
|
|
* set ID.
|
|
* @param registeredVariablesArray
|
|
* @param maxNumberOfVariables
|
|
*/
|
|
SharedSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables);
|
|
|
|
/**
|
|
* @brief Simple constructor, if the dataset is not the owner by
|
|
* a class with a HK manager.
|
|
* @details
|
|
* This constructor won't create components required for periodic handling
|
|
* and it also won't try to deduce the HK manager because no SID is
|
|
* supplied. This function should therefore be called by classes which need
|
|
* to access pool variables from different creators.
|
|
*
|
|
* If the class is intended to access pool variables from different
|
|
* creators, the third argument should be set to true. The mutex
|
|
* properties can be set with #setReadCommitProtectionBehaviour .
|
|
* @param registeredVariablesArray
|
|
* @param maxNumberOfVariables
|
|
* @param protectEveryReadCommitCall If the pool variables are created by
|
|
* multiple creators, this flag can be set to protect all read and
|
|
* commit calls separately.
|
|
*/
|
|
SharedSetBase(PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables,
|
|
bool protectEveryReadCommitCall = true);
|
|
|
|
/**
|
|
* @brief The destructor automatically manages writing the valid
|
|
* information of variables.
|
|
* @details
|
|
* In case the data set was read out, but not committed (indicated by state),
|
|
* the destructor parses all variables that are still registered to the set.
|
|
* For each, the valid flag in the data pool is set to "invalid".
|
|
*/
|
|
~SharedSetBase() override;
|
|
|
|
/* The copy constructor and assingment constructor are forbidden for now.
|
|
The use-cases are limited and the first step would be to implement them properly for the
|
|
base class */
|
|
SharedSetBase(const SharedSetBase& otherSet) = delete;
|
|
const SharedSetBase& operator=(const SharedSetBase& otherSet) = delete;
|
|
|
|
/**
|
|
* Helper functions used to set all currently contained variables to read-only.
|
|
* It is recommended to call this in set constructors intended to be used
|
|
* by data consumers to prevent accidentally changing pool data.
|
|
*/
|
|
void setAllVariablesReadOnly();
|
|
|
|
[[nodiscard]] virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
|
Endianness streamEndianness) const override;
|
|
|
|
[[nodiscard]] ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize,
|
|
SerializeIF::Endianness streamEndianness) const override;
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
Endianness streamEndianness) override;
|
|
|
|
[[nodiscard]] virtual ReturnValue_t serializeWithValidityBlob(uint8_t** buffer, size_t* size,
|
|
size_t maxSize,
|
|
Endianness streamEndianness) const;
|
|
|
|
[[nodiscard]] dp::sid_t getStructureId() const;
|
|
|
|
[[nodiscard]] size_t getSerializedSize() const override;
|
|
|
|
ReturnValue_t serializeLocalPoolIds(uint8_t** buffer, size_t* size, size_t maxSize,
|
|
SerializeIF::Endianness streamEndianness) const;
|
|
[[nodiscard]] size_t getLocalPoolIdsSerializedSize() const;
|
|
|
|
object_id_t getCreatorObjectId();
|
|
|
|
[[nodiscard]] bool getReportingEnabled() const;
|
|
void setReportingEnabled(bool enabled);
|
|
|
|
/**
|
|
* Returns the current periodic HK generation interval this set
|
|
* belongs to a HK manager and the interval is not 0. Otherwise,
|
|
* returns 0.0
|
|
* @return
|
|
*/
|
|
[[nodiscard]] float getCollectionInterval() const;
|
|
|
|
/**
|
|
* @brief Can be overwritten by a specific implementation of a dataset to print the set.
|
|
*/
|
|
virtual void printSet();
|
|
|
|
ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::BLOCKING,
|
|
dur_millis_t timeoutMs = 0) override;
|
|
ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::BLOCKING,
|
|
dur_millis_t timeoutMs = 0) override;
|
|
uint16_t getFillCount() const override;
|
|
|
|
ReturnValue_t registerVariable(PoolVariableIF* variable) override;
|
|
|
|
void setContainer(PoolVariableIF** variablesContainer);
|
|
PoolVariableIF** getContainer() const;
|
|
|
|
protected:
|
|
PoolDataSetBase base;
|
|
|
|
sid_t sid;
|
|
//! This mutex is used if the data is created by one object only.
|
|
MutexIF* mutexIfSingleDataCreator = nullptr;
|
|
|
|
/**
|
|
* Used for periodic generation.
|
|
*/
|
|
bool reportingEnabled = false;
|
|
|
|
void initializePeriodicHelper(float collectionInterval, dur_millis_t minimumPeriodicInterval);
|
|
|
|
/**
|
|
* If the valid state of a dataset is always relevant to the whole
|
|
* data set we can use this flag.
|
|
*/
|
|
bool valid = false;
|
|
|
|
/**
|
|
* @brief This is a small helper function to facilitate locking
|
|
* the global data pool.
|
|
* @details
|
|
* It makes use of the lockDataPool method offered by the DataPool class.
|
|
*/
|
|
ReturnValue_t lockDataPool(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) override;
|
|
|
|
/**
|
|
* @brief This is a small helper function to facilitate
|
|
* unlocking the global data pool
|
|
* @details
|
|
* It makes use of the freeDataPoolLock method offered by the DataPool class.
|
|
*/
|
|
ReturnValue_t unlockDataPool() override;
|
|
|
|
dp::SharedPool* sharedPool = nullptr;
|
|
};
|
|
|
|
} // namespace datapool
|