2020-09-29 14:42:48 +02:00
|
|
|
#ifndef FSFW_STORAGEMANAGER_POOLMANAGER_H_
|
|
|
|
#define FSFW_STORAGEMANAGER_POOLMANAGER_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "LocalPool.h"
|
2020-09-29 14:42:48 +02:00
|
|
|
#include "StorageAccessor.h"
|
2021-03-09 11:30:00 +01:00
|
|
|
#include "../ipc/MutexGuard.h"
|
2020-08-25 13:58:58 +02:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The PoolManager class provides an intermediate data storage with
|
|
|
|
* a fixed pool size policy for inter-process communication.
|
2020-10-15 13:43:23 +02:00
|
|
|
* @details
|
|
|
|
* Uses local pool calls but is thread safe by protecting most calls
|
|
|
|
* with a lock. The developer can lock the pool with the provided API
|
|
|
|
* if the lock needs to persists beyond the function call.
|
|
|
|
*
|
|
|
|
* Other than that, the class provides the same interface as the LocalPool
|
|
|
|
* class. The class is always registered as a system object as it is assumed
|
|
|
|
* it will always be used concurrently (if this is not the case, it is
|
|
|
|
* recommended to use the LocalPool class instead).
|
2020-05-29 16:48:53 +02:00
|
|
|
* @author Bastian Baetz
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-10-15 13:43:23 +02:00
|
|
|
class PoolManager: public LocalPool {
|
2020-05-29 16:37:46 +02:00
|
|
|
public:
|
2020-10-15 13:43:23 +02:00
|
|
|
PoolManager(object_id_t setObjectId, const LocalPoolConfig& poolConfig);
|
2020-05-29 16:37:46 +02:00
|
|
|
|
2020-09-29 14:42:48 +02:00
|
|
|
/**
|
|
|
|
* @brief In the PoolManager's destructor all allocated memory
|
|
|
|
* is freed.
|
|
|
|
*/
|
2020-05-29 16:37:46 +02:00
|
|
|
virtual ~PoolManager();
|
|
|
|
|
2020-10-15 13:43:23 +02:00
|
|
|
/**
|
|
|
|
* Set the default mutex timeout for internal calls.
|
|
|
|
* @param mutexTimeoutMs
|
|
|
|
*/
|
|
|
|
void setMutexTimeout(uint32_t mutexTimeoutMs);
|
|
|
|
|
2020-09-29 14:42:48 +02:00
|
|
|
/**
|
|
|
|
* @brief LocalPool overrides for thread-safety. Decorator function
|
|
|
|
* which wraps LocalPool calls with a mutex protection.
|
|
|
|
*/
|
2020-05-29 16:37:46 +02:00
|
|
|
ReturnValue_t deleteData(store_address_t) override;
|
|
|
|
ReturnValue_t deleteData(uint8_t* buffer, size_t size,
|
|
|
|
store_address_t* storeId = nullptr) override;
|
2020-06-04 15:03:29 +02:00
|
|
|
|
2020-10-15 13:43:23 +02:00
|
|
|
/**
|
|
|
|
* The developer is allowed to lock the mutex in case the lock needs
|
|
|
|
* to persist beyond the function calls which are not protected by the
|
|
|
|
* class.
|
|
|
|
* @param timeoutType
|
|
|
|
* @param timeoutMs
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
ReturnValue_t lockMutex(MutexIF::TimeoutType timeoutType,
|
|
|
|
uint32_t timeoutMs);
|
|
|
|
ReturnValue_t unlockMutex();
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
protected:
|
2020-06-23 11:06:54 +02:00
|
|
|
//! Default mutex timeout value to prevent permanent blocking.
|
2020-09-29 14:50:16 +02:00
|
|
|
uint32_t mutexTimeoutMs = 20;
|
2020-06-23 11:06:54 +02:00
|
|
|
|
2020-10-15 13:43:23 +02:00
|
|
|
ReturnValue_t reserveSpace(const size_t size, store_address_t* address,
|
2020-05-29 16:37:46 +02:00
|
|
|
bool ignoreFault) override;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
2020-05-29 16:37:46 +02:00
|
|
|
* @brief The mutex is created in the constructor and makes
|
|
|
|
* access mutual exclusive.
|
|
|
|
* @details Locking and unlocking is done during searching for free slots
|
|
|
|
* and deleting existing slots.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-05-29 16:37:46 +02:00
|
|
|
MutexIF* mutex;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-09-29 14:42:48 +02:00
|
|
|
#endif /* FSFW_STORAGEMANAGER_POOLMANAGER_H_ */
|