From f852c774f8e41a6ebf00b5cb6e5e24a815345837 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 27 Dec 2020 01:52:48 +0100 Subject: [PATCH 1/2] accessor test --- datapool/PoolDataSetIF.h | 6 ++-- datapool/PoolVariableIF.h | 40 ++----------------------- datapool/ReadCommitIF.h | 31 +++++++++++++++++++ datapoollocal/LocalDataPoolManager.cpp | 2 +- datapoollocal/PoolReadHelper.h | 41 ++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 datapool/ReadCommitIF.h create mode 100644 datapoollocal/PoolReadHelper.h diff --git a/datapool/PoolDataSetIF.h b/datapool/PoolDataSetIF.h index aa45fa54..99c06cfd 100644 --- a/datapool/PoolDataSetIF.h +++ b/datapool/PoolDataSetIF.h @@ -1,19 +1,17 @@ #ifndef FSFW_DATAPOOL_POOLDATASETIF_H_ #define FSFW_DATAPOOL_POOLDATASETIF_H_ +#include "ReadCommitIF.h" #include "DataSetIF.h" /** * @brief Extendes the DataSetIF by adding abstract functions to lock * and unlock a data pool and read/commit semantics. */ -class PoolDataSetIF: public DataSetIF { +class PoolDataSetIF: public DataSetIF, public ReadCommitIF { public: virtual~ PoolDataSetIF() {}; - virtual ReturnValue_t read(dur_millis_t lockTimeout) = 0; - virtual ReturnValue_t commit(dur_millis_t lockTimeout) = 0; - /** * @brief Most underlying data structures will have a pool like structure * and will require a lock and unlock mechanism to ensure diff --git a/datapool/PoolVariableIF.h b/datapool/PoolVariableIF.h index cd15f744..9740fc12 100644 --- a/datapool/PoolVariableIF.h +++ b/datapool/PoolVariableIF.h @@ -3,6 +3,7 @@ #include "../returnvalues/HasReturnvaluesIF.h" #include "../serialize/SerializeIF.h" +#include "ReadCommitIF.h" /** * @brief This interface is used to control data pool @@ -17,9 +18,9 @@ * @author Bastian Baetz * @ingroup data_pool */ -class PoolVariableIF : public SerializeIF { +class PoolVariableIF : public SerializeIF, + public ReadCommitIF { friend class PoolDataSetBase; - friend class GlobDataSet; friend class LocalPoolDataSetBase; public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::POOL_VARIABLE_IF; @@ -57,41 +58,6 @@ public: */ virtual void setValid(bool validity) = 0; - /** - * @brief The commit call shall write back a newly calculated local - * value to the data pool. - * @details - * It is assumed that these calls are implemented in a thread-safe manner! - */ - virtual ReturnValue_t commit(uint32_t lockTimeout) = 0; - /** - * @brief The read call shall read the value of this parameter from - * the data pool and store the content locally. - * @details - * It is assumbed that these calls are implemented in a thread-safe manner! - */ - virtual ReturnValue_t read(uint32_t lockTimeout) = 0; - -protected: - - /** - * @brief Same as commit with the difference that comitting will be - * performed without a lock - * @return - * This can be used if the lock protection is handled externally - * to avoid the overhead of locking and unlocking consecutively. - * Declared protected to avoid free public usage. - */ - virtual ReturnValue_t readWithoutLock() = 0; - /** - * @brief Same as commit with the difference that comitting will be - * performed without a lock - * @return - * This can be used if the lock protection is handled externally - * to avoid the overhead of locking and unlocking consecutively. - * Declared protected to avoid free public usage. - */ - virtual ReturnValue_t commitWithoutLock() = 0; }; using pool_rwm_t = PoolVariableIF::ReadWriteMode_t; diff --git a/datapool/ReadCommitIF.h b/datapool/ReadCommitIF.h new file mode 100644 index 00000000..0cdce371 --- /dev/null +++ b/datapool/ReadCommitIF.h @@ -0,0 +1,31 @@ +#ifndef FSFW_DATAPOOL_READCOMMITIF_H_ +#define FSFW_DATAPOOL_READCOMMITIF_H_ + +#include + +/** + * @brief Common interface for all software objects which employ read-commit + * semantics. + */ +class ReadCommitIF { +public: + virtual ~ReadCommitIF() {} + virtual ReturnValue_t read(uint32_t mutexTimeout) = 0; + virtual ReturnValue_t commit(uint32_t mutexTimeout) = 0; + +protected: + + //! Optional and protected because this is interesting for classes grouping + //! members with commit and read semantics where the lock is only necessary + //! once. + virtual ReturnValue_t readWithoutLock() { + return read(20); + } + + virtual ReturnValue_t commitWithoutLock() { + return commit(20); + } +}; + + +#endif /* FSFW_DATAPOOL_READCOMMITIF_H_ */ diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index f649a362..5f0d15d3 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -577,7 +577,7 @@ ReturnValue_t LocalDataPoolManager::printPoolEntry( if (poolIter == localPoolMap.end()) { sif::debug << "HousekeepingManager::fechPoolEntry:" << " Pool entry not found." << std::endl; - return POOL_ENTRY_NOT_FOUND; + return HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND; } poolIter->second->print(); return HasReturnvaluesIF::RETURN_OK; diff --git a/datapoollocal/PoolReadHelper.h b/datapoollocal/PoolReadHelper.h new file mode 100644 index 00000000..4fe506ee --- /dev/null +++ b/datapoollocal/PoolReadHelper.h @@ -0,0 +1,41 @@ +#ifndef FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_ +#define FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_ + +#include +#include + +/** + * @brief Helper class to read data sets or pool variables + */ +class PoolReadHelper { +public: + PoolReadHelper(ReadCommitIF* readObject, uint32_t mutexTimeout = 20): + readObject(readObject), mutexTimeout(mutexTimeout) { + if(readObject != nullptr) { + readResult = readObject->read(mutexTimeout); +#if FSFW_PRINT_VERBOSITY_LEVEL == 1 + sif::error << "PoolReadHelper: Read failed!" << std::endl; +#endif + } + } + + ReturnValue_t getReadResult() const { + return readResult; + } + + ~PoolReadHelper() { + if(readObject != nullptr) { + readObject->commit(mutexTimeout); + } + + } + +private: + ReadCommitIF* readObject = nullptr; + ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK; + uint32_t mutexTimeout = 20; +}; + + + +#endif /* FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_ */ From ed473d0a1bbd6bc80c3526eb2a02b8586bbfeec7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 27 Dec 2020 02:04:45 +0100 Subject: [PATCH 2/2] bugfix --- datapoollocal/LocalPoolDataSetBase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 7eabd368..d9b6a221 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -192,7 +192,7 @@ protected: */ ReturnValue_t unlockDataPool() override; - LocalDataPoolManager* hkManager; + LocalDataPoolManager* hkManager = nullptr; /** * Set n-th bit of a byte, with n being the position from 0