From ab7c3480f58009afb2feb584f684870a158b97e6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 10:30:22 +0200 Subject: [PATCH 1/9] storage manager update --- .../storagemanager/ConstStorageAccessor.cpp | 8 +-- .../storagemanager/ConstStorageAccessor.h | 13 ++-- src/fsfw/storagemanager/LocalPool.cpp | 59 ++++++++----------- src/fsfw/storagemanager/LocalPool.h | 24 ++++---- src/fsfw/storagemanager/PoolManager.h | 8 +-- src/fsfw/storagemanager/StorageAccessor.cpp | 4 +- src/fsfw/storagemanager/StorageAccessor.h | 7 ++- src/fsfw/storagemanager/StorageManagerIF.h | 56 ++++++++++++++---- 8 files changed, 103 insertions(+), 76 deletions(-) diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.cpp b/src/fsfw/storagemanager/ConstStorageAccessor.cpp index f64334f7..e39fa36b 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.cpp +++ b/src/fsfw/storagemanager/ConstStorageAccessor.cpp @@ -19,7 +19,7 @@ ConstStorageAccessor::~ConstStorageAccessor() { } } -ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) +ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) noexcept : constDataPointer(other.constDataPointer), storeId(other.storeId), size_(other.size_), @@ -30,7 +30,7 @@ ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other) other.store = nullptr; } -ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) { +ConstStorageAccessor& ConstStorageAccessor::operator=(ConstStorageAccessor&& other) noexcept { constDataPointer = other.constDataPointer; storeId = other.storeId; store = other.store; @@ -84,7 +84,7 @@ void ConstStorageAccessor::print() const { arrayprinter::print(constDataPointer, size_); } -void ConstStorageAccessor::assignStore(StorageManagerIF* store) { +void ConstStorageAccessor::assignStore(StorageManagerIF* store_) { internalState = AccessState::ASSIGNED; - this->store = store; + store = store_; } diff --git a/src/fsfw/storagemanager/ConstStorageAccessor.h b/src/fsfw/storagemanager/ConstStorageAccessor.h index 9cad346c..0911c6d9 100644 --- a/src/fsfw/storagemanager/ConstStorageAccessor.h +++ b/src/fsfw/storagemanager/ConstStorageAccessor.h @@ -23,6 +23,7 @@ class ConstStorageAccessor { //! StorageManager classes have exclusive access to private variables. friend class PoolManager; friend class LocalPool; + friend class StorageManagerIF; public: /** @@ -30,7 +31,7 @@ class ConstStorageAccessor { * entry to access. * @param storeId */ - ConstStorageAccessor(store_address_t storeId); + explicit ConstStorageAccessor(store_address_t storeId); ConstStorageAccessor(store_address_t storeId, StorageManagerIF* store); /** @@ -43,7 +44,7 @@ class ConstStorageAccessor { * @brief Returns a pointer to the read-only data * @return */ - const uint8_t* data() const; + [[nodiscard]] const uint8_t* data() const; /** * @brief Copies the read-only data to the supplied pointer @@ -61,13 +62,13 @@ class ConstStorageAccessor { * Get the size of the data * @return */ - size_t size() const; + [[nodiscard]] size_t size() const; /** * Get the storage ID. * @return */ - store_address_t getId() const; + [[nodiscard]] store_address_t getId() const; void print() const; @@ -79,8 +80,8 @@ class ConstStorageAccessor { * @param * @return */ - ConstStorageAccessor& operator=(ConstStorageAccessor&&); - ConstStorageAccessor(ConstStorageAccessor&&); + ConstStorageAccessor& operator=(ConstStorageAccessor&&) noexcept; + ConstStorageAccessor(ConstStorageAccessor&&) noexcept; //! The copy ctor and copy assignemnt should be deleted implicitely //! according to https://foonathan.net/2019/02/special-member-functions/ diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index d907a9b3..970b05f5 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -29,7 +29,7 @@ LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig, } } -LocalPool::~LocalPool(void) {} +LocalPool::~LocalPool() = default; ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size, bool ignoreFault) { @@ -48,22 +48,6 @@ ReturnValue_t LocalPool::getData(store_address_t packetId, const uint8_t** packe return status; } -ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& storeAccessor) { - uint8_t* tempData = nullptr; - ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_); - storeAccessor.assignStore(this); - storeAccessor.constDataPointer = tempData; - return status; -} - -ConstAccessorPair LocalPool::getData(store_address_t storeId) { - uint8_t* tempData = nullptr; - ConstStorageAccessor constAccessor(storeId, this); - ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_); - constAccessor.constDataPointer = tempData; - return ConstAccessorPair(status, std::move(constAccessor)); -} - ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t size, uint8_t** pData, bool ignoreFault) { ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); @@ -75,20 +59,6 @@ ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t return status; } -AccessorPair LocalPool::modifyData(store_address_t storeId) { - StorageAccessor accessor(storeId, this); - ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); - accessor.assignConstPointer(); - return AccessorPair(status, std::move(accessor)); -} - -ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& storeAccessor) { - storeAccessor.assignStore(this); - ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer, &storeAccessor.size_); - storeAccessor.assignConstPointer(); - return status; -} - ReturnValue_t LocalPool::modifyData(store_address_t storeId, uint8_t** packetPtr, size_t* size) { ReturnValue_t status = returnvalue::FAILED; if (storeId.poolIndex >= NUMBER_OF_SUBPOOLS) { @@ -197,8 +167,7 @@ void LocalPool::clearStore() { } } -ReturnValue_t LocalPool::reserveSpace(const size_t size, store_address_t* storeId, - bool ignoreFault) { +ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, bool ignoreFault) { ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex); if (status != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -349,3 +318,27 @@ bool LocalPool::hasDataAtId(store_address_t storeId) const { } return false; } + +ReturnValue_t LocalPool::getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) { + return StorageManagerIF::getFreeElement(storeId, size, pData); +} + +ConstAccessorPair LocalPool::getData(store_address_t storeId) { + return StorageManagerIF::getData(storeId); +} + +ReturnValue_t LocalPool::addData(store_address_t* storeId, const uint8_t* data, size_t size) { + return StorageManagerIF::addData(storeId, data, size); +} + +ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& accessor) { + return StorageManagerIF::getData(storeId, accessor); +} + +ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& accessor) { + return StorageManagerIF::modifyData(storeId, accessor); +} + +AccessorPair LocalPool::modifyData(store_address_t storeId) { + return StorageManagerIF::modifyData(storeId); +} diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index a82da971..54d704e6 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -87,21 +87,23 @@ class LocalPool : public SystemObject, public StorageManagerIF { * Documentation: See StorageManagerIF.h */ ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, - bool ignoreFault = false) override; - ReturnValue_t getFreeElement(store_address_t* storeId, const size_t size, uint8_t** pData, - bool ignoreFault = false) override; + bool ignoreFault) override; + ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; + + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, + bool ignoreFault) override; ConstAccessorPair getData(store_address_t storeId) override; - ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& constAccessor) override; + ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; AccessorPair modifyData(store_address_t storeId) override; - ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& storeAccessor) override; ReturnValue_t modifyData(store_address_t storeId, uint8_t** packet_ptr, size_t* size) override; + ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) override; - virtual ReturnValue_t deleteData(store_address_t storeId) override; - virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size, - store_address_t* storeId = nullptr) override; + ReturnValue_t deleteData(store_address_t storeId) override; + ReturnValue_t deleteData(uint8_t* ptr, size_t size, store_address_t* storeId) override; /** * Get the total size of allocated memory for pool data. @@ -131,8 +133,8 @@ class LocalPool : public SystemObject, public StorageManagerIF { * Get number sub pools. Each pool has pages with a specific bucket size. * @return */ - max_subpools_t getNumberOfSubPools() const override; - bool hasDataAtId(store_address_t storeId) const override; + [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; + [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; protected: /** @@ -142,7 +144,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { * @return - returnvalue::OK on success, * - the return codes of #getPoolIndex or #findEmpty otherwise. */ - virtual ReturnValue_t reserveSpace(const size_t size, store_address_t* address, bool ignoreFault); + virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault); private: /** diff --git a/src/fsfw/storagemanager/PoolManager.h b/src/fsfw/storagemanager/PoolManager.h index 0951a518..eaa978ef 100644 --- a/src/fsfw/storagemanager/PoolManager.h +++ b/src/fsfw/storagemanager/PoolManager.h @@ -27,7 +27,7 @@ class PoolManager : public LocalPool { * @brief In the PoolManager's destructor all allocated memory * is freed. */ - virtual ~PoolManager(); + ~PoolManager() override; /** * Set the default mutex timeout for internal calls. @@ -40,8 +40,7 @@ class PoolManager : public LocalPool { * which wraps LocalPool calls with a mutex protection. */ ReturnValue_t deleteData(store_address_t) override; - ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId = nullptr) override; + ReturnValue_t deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) override; /** * The developer is allowed to lock the mutex in case the lock needs @@ -58,8 +57,7 @@ class PoolManager : public LocalPool { //! Default mutex timeout value to prevent permanent blocking. uint32_t mutexTimeoutMs = 20; - ReturnValue_t reserveSpace(const size_t size, store_address_t* address, - bool ignoreFault) override; + ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault) override; /** * @brief The mutex is created in the constructor and makes diff --git a/src/fsfw/storagemanager/StorageAccessor.cpp b/src/fsfw/storagemanager/StorageAccessor.cpp index 8a96dcec..b576a113 100644 --- a/src/fsfw/storagemanager/StorageAccessor.cpp +++ b/src/fsfw/storagemanager/StorageAccessor.cpp @@ -10,7 +10,7 @@ StorageAccessor::StorageAccessor(store_address_t storeId) : ConstStorageAccessor StorageAccessor::StorageAccessor(store_address_t storeId, StorageManagerIF* store) : ConstStorageAccessor(storeId, store) {} -StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { +StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) noexcept { // Call the parent move assignment and also assign own member. dataPointer = other.dataPointer; ConstStorageAccessor::operator=(std::move(other)); @@ -18,7 +18,7 @@ StorageAccessor& StorageAccessor::operator=(StorageAccessor&& other) { } // Call the parent move ctor and also transfer own member. -StorageAccessor::StorageAccessor(StorageAccessor&& other) +StorageAccessor::StorageAccessor(StorageAccessor&& other) noexcept : ConstStorageAccessor(std::move(other)), dataPointer(other.dataPointer) {} ReturnValue_t StorageAccessor::getDataCopy(uint8_t* pointer, size_t maxSize) { diff --git a/src/fsfw/storagemanager/StorageAccessor.h b/src/fsfw/storagemanager/StorageAccessor.h index 5e8b25e4..b6c5dc14 100644 --- a/src/fsfw/storagemanager/StorageAccessor.h +++ b/src/fsfw/storagemanager/StorageAccessor.h @@ -12,9 +12,10 @@ class StorageAccessor : public ConstStorageAccessor { //! StorageManager classes have exclusive access to private variables. friend class PoolManager; friend class LocalPool; + friend class StorageManagerIF; public: - StorageAccessor(store_address_t storeId); + explicit StorageAccessor(store_address_t storeId); StorageAccessor(store_address_t storeId, StorageManagerIF* store); /** @@ -25,8 +26,8 @@ class StorageAccessor : public ConstStorageAccessor { * @param * @return */ - StorageAccessor& operator=(StorageAccessor&&); - StorageAccessor(StorageAccessor&&); + StorageAccessor& operator=(StorageAccessor&&) noexcept; + StorageAccessor(StorageAccessor&&) noexcept; ReturnValue_t write(uint8_t* data, size_t size, uint16_t offset = 0); uint8_t* data(); diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 228d380b..2845e581 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -67,7 +67,12 @@ class StorageManagerIF { * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault = false) = 0; + bool ignoreFault) = 0; + + virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) { + return addData(storageId, data, size, false); + } + /** * @brief With deleteData, the storageManager frees the memory region * identified by packet_id. @@ -86,9 +91,10 @@ class StorageManagerIF { * @return @li returnvalue::OK on success. * @li failure code if deletion did not work */ - virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, - store_address_t* storeId = nullptr) = 0; - + virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, store_address_t* storeId) = 0; + virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size) { + return deleteData(buffer, size, nullptr); + } /** * @brief Access the data by supplying a store ID. * @details @@ -97,7 +103,13 @@ class StorageManagerIF { * @param storeId * @return Pair of return value and a ConstStorageAccessor instance */ - virtual ConstAccessorPair getData(store_address_t storeId) = 0; + virtual ConstAccessorPair getData(store_address_t storeId) { + uint8_t* tempData = nullptr; + ConstStorageAccessor constAccessor(storeId, this); + ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_); + constAccessor.constDataPointer = tempData; + return {status, std::move(constAccessor)}; + } /** * @brief Access the data by supplying a store ID and a helper @@ -106,7 +118,13 @@ class StorageManagerIF { * @param constAccessor Wrapper function to access store data. * @return */ - virtual ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& constAccessor) = 0; + virtual ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) { + uint8_t* tempData = nullptr; + ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_); + accessor.assignStore(this); + accessor.constDataPointer = tempData; + return status; + } /** * @brief getData returns an address to data and the size of the data @@ -127,7 +145,12 @@ class StorageManagerIF { * @param storeId * @return Pair of return value and StorageAccessor helper */ - virtual AccessorPair modifyData(store_address_t storeId) = 0; + virtual AccessorPair modifyData(store_address_t storeId) { + StorageAccessor accessor(storeId, this); + ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); + accessor.assignConstPointer(); + return {status, std::move(accessor)}; + } /** * Modify data by supplying a store ID and a StorageAccessor helper instance. @@ -135,7 +158,12 @@ class StorageManagerIF { * @param accessor Helper class to access the modifiable data. * @return */ - virtual ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) = 0; + virtual ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) { + accessor.assignStore(this); + ReturnValue_t status = modifyData(storeId, &accessor.dataPointer, &accessor.size_); + accessor.assignConstPointer(); + return status; + } /** * Get pointer and size of modifiable data by supplying the storeId @@ -154,12 +182,16 @@ class StorageManagerIF { * written to p_data! * @param storageId A pointer to the storageId to retrieve. * @param size The size of the space to be reserved. - * @param p_data A pointer to the element data is returned here. - * @return Returns @li returnvalue::OK if data was added. + * @param dataPtr A pointer to the element data is returned here. + * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** p_data, - bool ignoreFault = false) = 0; + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr, + bool ignoreFault) = 0; + + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) { + return getFreeElement(storageId, size, dataPtr, false); + } [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; From b3c0e2461154dcbacbd7ba958dff58fdd9289f44 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 10:31:55 +0200 Subject: [PATCH 2/9] bump changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe567de..da557d70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). for other modules PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/655 which also includes a migration guide +- Move some generic `StorageManagerIF` implementations from `LocalPool` to + interface itself so it can be re-used more easily. Also add new + abstract function `bool hasDataAtId(store_address_t storeId) const`. + PR: # [v5.0.0] 25.07.2022 From e063b44899a3e6a74b0a54b9ae1533af723cec83 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 15 Sep 2022 10:32:38 +0200 Subject: [PATCH 3/9] add link to PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da557d70..476632df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Move some generic `StorageManagerIF` implementations from `LocalPool` to interface itself so it can be re-used more easily. Also add new abstract function `bool hasDataAtId(store_address_t storeId) const`. - PR: + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/685 # [v5.0.0] 25.07.2022 From bfe120636c098c2fea205ff8fecee6cc1d3b92d3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 17 Oct 2022 15:08:46 +0200 Subject: [PATCH 4/9] this should have the same effect --- src/fsfw/storagemanager/LocalPool.cpp | 24 ------------------------ src/fsfw/storagemanager/LocalPool.h | 11 +++++------ 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 970b05f5..7d37507a 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -318,27 +318,3 @@ bool LocalPool::hasDataAtId(store_address_t storeId) const { } return false; } - -ReturnValue_t LocalPool::getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) { - return StorageManagerIF::getFreeElement(storeId, size, pData); -} - -ConstAccessorPair LocalPool::getData(store_address_t storeId) { - return StorageManagerIF::getData(storeId); -} - -ReturnValue_t LocalPool::addData(store_address_t* storeId, const uint8_t* data, size_t size) { - return StorageManagerIF::addData(storeId, data, size); -} - -ReturnValue_t LocalPool::getData(store_address_t storeId, ConstStorageAccessor& accessor) { - return StorageManagerIF::getData(storeId, accessor); -} - -ReturnValue_t LocalPool::modifyData(store_address_t storeId, StorageAccessor& accessor) { - return StorageManagerIF::modifyData(storeId, accessor); -} - -AccessorPair LocalPool::modifyData(store_address_t storeId) { - return StorageManagerIF::modifyData(storeId); -} diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 54d704e6..d3494f4b 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -88,19 +88,13 @@ class LocalPool : public SystemObject, public StorageManagerIF { */ ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, bool ignoreFault) override; - ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; - ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, bool ignoreFault) override; - ConstAccessorPair getData(store_address_t storeId) override; - ReturnValue_t getData(store_address_t storeId, ConstStorageAccessor& accessor) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; - AccessorPair modifyData(store_address_t storeId) override; ReturnValue_t modifyData(store_address_t storeId, uint8_t** packet_ptr, size_t* size) override; - ReturnValue_t modifyData(store_address_t storeId, StorageAccessor& accessor) override; ReturnValue_t deleteData(store_address_t storeId) override; ReturnValue_t deleteData(uint8_t* ptr, size_t size, store_address_t* storeId) override; @@ -136,6 +130,11 @@ class LocalPool : public SystemObject, public StorageManagerIF { [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; + using StorageManagerIF::getFreeElement; + using StorageManagerIF::getData; + using StorageManagerIF::addData; + using StorageManagerIF::modifyData; + protected: /** * With this helper method, a free element of @c size is reserved. From 54ad6b30168d7a83940cd97672fb71e9a9dfd657 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 14:39:05 +0200 Subject: [PATCH 5/9] add some docs --- src/fsfw/storagemanager/LocalPool.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index d3494f4b..1472ee25 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -130,6 +130,9 @@ class LocalPool : public SystemObject, public StorageManagerIF { [[nodiscard]] max_subpools_t getNumberOfSubPools() const override; [[nodiscard]] bool hasDataAtId(store_address_t storeId) const override; + // Using functions provided by StorageManagerIF requires either a fully qualified path + // like for example localPool.StorageManagerIF::getFreeElement(...) or re-exporting + // the fully qualified path with the using directive. using StorageManagerIF::getFreeElement; using StorageManagerIF::getData; using StorageManagerIF::addData; From 4db124c6805d0778f1857a9d6bf6b25c1c37c587 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 15:41:29 +0200 Subject: [PATCH 6/9] ignore fault --- src/fsfw/storagemanager/LocalPool.cpp | 11 +++++------ src/fsfw/storagemanager/LocalPool.h | 11 +++++------ src/fsfw/storagemanager/StorageManagerIF.h | 14 ++------------ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/fsfw/storagemanager/LocalPool.cpp b/src/fsfw/storagemanager/LocalPool.cpp index 7d37507a..b62c19b6 100644 --- a/src/fsfw/storagemanager/LocalPool.cpp +++ b/src/fsfw/storagemanager/LocalPool.cpp @@ -31,9 +31,8 @@ LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig, LocalPool::~LocalPool() = default; -ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault) { - ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); +ReturnValue_t LocalPool::addData(store_address_t* storageId, const uint8_t* data, size_t size) { + ReturnValue_t status = reserveSpace(size, storageId); if (status == returnvalue::OK) { write(*storageId, data, size); } @@ -49,8 +48,8 @@ ReturnValue_t LocalPool::getData(store_address_t packetId, const uint8_t** packe } ReturnValue_t LocalPool::getFreeElement(store_address_t* storageId, const size_t size, - uint8_t** pData, bool ignoreFault) { - ReturnValue_t status = reserveSpace(size, storageId, ignoreFault); + uint8_t** pData) { + ReturnValue_t status = reserveSpace(size, storageId); if (status == returnvalue::OK) { *pData = &store[storageId->poolIndex][getRawPosition(*storageId)]; } else { @@ -167,7 +166,7 @@ void LocalPool::clearStore() { } } -ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId, bool ignoreFault) { +ReturnValue_t LocalPool::reserveSpace(size_t size, store_address_t* storeId) { ReturnValue_t status = getSubPoolIndex(size, &storeId->poolIndex); if (status != returnvalue::OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index 1472ee25..bb88842b 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -86,11 +86,9 @@ class LocalPool : public SystemObject, public StorageManagerIF { /** * Documentation: See StorageManagerIF.h */ - ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size, - bool ignoreFault) override; + ReturnValue_t addData(store_address_t* storeId, const uint8_t* data, size_t size) override; - ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData, - bool ignoreFault) override; + ReturnValue_t getFreeElement(store_address_t* storeId, size_t size, uint8_t** pData) override; ReturnValue_t getData(store_address_t storeId, const uint8_t** packet_ptr, size_t* size) override; @@ -135,7 +133,6 @@ class LocalPool : public SystemObject, public StorageManagerIF { // the fully qualified path with the using directive. using StorageManagerIF::getFreeElement; using StorageManagerIF::getData; - using StorageManagerIF::addData; using StorageManagerIF::modifyData; protected: @@ -146,7 +143,7 @@ class LocalPool : public SystemObject, public StorageManagerIF { * @return - returnvalue::OK on success, * - the return codes of #getPoolIndex or #findEmpty otherwise. */ - virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault); + virtual ReturnValue_t reserveSpace(size_t size, store_address_t* address); private: /** @@ -190,6 +187,8 @@ class LocalPool : public SystemObject, public StorageManagerIF { std::vector> sizeLists = std::vector>(NUMBER_OF_SUBPOOLS); + bool ignoreFault = false; + //! A variable to determine whether higher n pools are used if //! the store is full. bool spillsToHigherPools = false; diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 2845e581..5d804e44 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -66,12 +66,7 @@ class StorageManagerIF { * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size, - bool ignoreFault) = 0; - - virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) { - return addData(storageId, data, size, false); - } + virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t* data, size_t size) = 0; /** * @brief With deleteData, the storageManager frees the memory region @@ -186,12 +181,7 @@ class StorageManagerIF { * @return Returns @returnvalue::OK if data was added. * @returnvalue::FAILED if data could not be added, storageId is unchanged then. */ - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr, - bool ignoreFault) = 0; - - virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) { - return getFreeElement(storageId, size, dataPtr, false); - } + virtual ReturnValue_t getFreeElement(store_address_t* storageId, size_t size, uint8_t** dataPtr) = 0; [[nodiscard]] virtual bool hasDataAtId(store_address_t storeId) const = 0; From d26f230beeec08e72856df64b81966a3f9d840a2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 15:43:20 +0200 Subject: [PATCH 7/9] builds --- src/fsfw/storagemanager/PoolManager.cpp | 5 ++--- src/fsfw/storagemanager/PoolManager.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fsfw/storagemanager/PoolManager.cpp b/src/fsfw/storagemanager/PoolManager.cpp index 41e140b2..840a7dcc 100644 --- a/src/fsfw/storagemanager/PoolManager.cpp +++ b/src/fsfw/storagemanager/PoolManager.cpp @@ -9,10 +9,9 @@ PoolManager::PoolManager(object_id_t setObjectId, const LocalPoolConfig& localPo PoolManager::~PoolManager() { MutexFactory::instance()->deleteMutex(mutex); } -ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* address, - bool ignoreFault) { +ReturnValue_t PoolManager::reserveSpace(const size_t size, store_address_t* address) { MutexGuard mutexHelper(mutex, MutexIF::TimeoutType::WAITING, mutexTimeoutMs); - ReturnValue_t status = LocalPool::reserveSpace(size, address, ignoreFault); + ReturnValue_t status = LocalPool::reserveSpace(size, address); return status; } diff --git a/src/fsfw/storagemanager/PoolManager.h b/src/fsfw/storagemanager/PoolManager.h index eaa978ef..aa8c93dd 100644 --- a/src/fsfw/storagemanager/PoolManager.h +++ b/src/fsfw/storagemanager/PoolManager.h @@ -57,7 +57,7 @@ class PoolManager : public LocalPool { //! Default mutex timeout value to prevent permanent blocking. uint32_t mutexTimeoutMs = 20; - ReturnValue_t reserveSpace(size_t size, store_address_t* address, bool ignoreFault) override; + ReturnValue_t reserveSpace(size_t size, store_address_t* address) override; /** * @brief The mutex is created in the constructor and makes From 81a7de28147a0c386ff29269c36d0b00db1f9ad7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 24 Oct 2022 16:39:32 +0200 Subject: [PATCH 8/9] make dtor virtual --- src/fsfw/storagemanager/StorageManagerIF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/storagemanager/StorageManagerIF.h b/src/fsfw/storagemanager/StorageManagerIF.h index 5d804e44..f9fb33f5 100644 --- a/src/fsfw/storagemanager/StorageManagerIF.h +++ b/src/fsfw/storagemanager/StorageManagerIF.h @@ -55,7 +55,7 @@ class StorageManagerIF { /** * @brief This is the empty virtual destructor as required for C++ interfaces. */ - ~StorageManagerIF() = default; + virtual ~StorageManagerIF() = default; /** * @brief With addData, a free storage position is allocated and data * stored there. From 1bea2344f68d8d86746dc5416133b8a630fbc6bc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Nov 2022 14:21:00 +0100 Subject: [PATCH 9/9] remove using declaraction --- src/fsfw/storagemanager/LocalPool.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fsfw/storagemanager/LocalPool.h b/src/fsfw/storagemanager/LocalPool.h index bb88842b..f82acd54 100644 --- a/src/fsfw/storagemanager/LocalPool.h +++ b/src/fsfw/storagemanager/LocalPool.h @@ -131,7 +131,6 @@ class LocalPool : public SystemObject, public StorageManagerIF { // Using functions provided by StorageManagerIF requires either a fully qualified path // like for example localPool.StorageManagerIF::getFreeElement(...) or re-exporting // the fully qualified path with the using directive. - using StorageManagerIF::getFreeElement; using StorageManagerIF::getData; using StorageManagerIF::modifyData;