moved pool accessor fuctions to local pool

This commit is contained in:
Robin Müller 2020-05-12 16:32:01 +02:00
parent 5af0c15dfc
commit 6c70abfe16
6 changed files with 82 additions and 16 deletions

View File

@ -6,7 +6,8 @@
#include <framework/storagemanager/StorageManagerIF.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/internalError/InternalErrorReporterIF.h>
#include <string.h>
#include <framework/storagemanager/StorageAccessor.h>
#include <cstring>
/**
* @brief The LocalPool class provides an intermediate data storage with
@ -67,10 +68,17 @@ public:
size_t size, bool ignoreFault = false) override;
ReturnValue_t getFreeElement(store_address_t* storageId,const size_t size,
uint8_t** p_data, bool ignoreFault = false) override;
ConstAccessorPair getData(store_address_t packet_id) override;
ReturnValue_t getData(store_address_t packet_id, ConstStorageAccessor&) override;
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
size_t * size) override;
AccessorPair modifyData(store_address_t packet_id) override;
ReturnValue_t modifyData(store_address_t packet_id, StorageAccessor&) override;
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
size_t * size) override;
virtual ReturnValue_t deleteData(store_address_t) override;
virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size,
store_address_t* storeId = NULL) override;

View File

@ -121,8 +121,8 @@ inline LocalPool<NUMBER_OF_POOLS>::~LocalPool(void) {
}
}
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::addData(store_address_t* storageId,
template<uint8_t NUMBER_OF_POOLS> inline
ReturnValue_t LocalPool<NUMBER_OF_POOLS>::addData(store_address_t* storageId,
const uint8_t* data, size_t size, bool ignoreFault) {
ReturnValue_t status = reserveSpace(size, storageId, ignoreFault);
if (status == RETURN_OK) {
@ -144,6 +144,25 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getFreeElement(
return status;
}
template<uint8_t NUMBER_OF_POOLS>
inline ConstAccessorPair LocalPool<NUMBER_OF_POOLS>::getData(
store_address_t storeId) {
uint8_t* tempData = nullptr;
ConstStorageAccessor constAccessor(storeId);
ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_);
constAccessor.constDataPointer = tempData;
return ConstAccessorPair(status, std::move(constAccessor));
}
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(store_address_t storeId,
ConstStorageAccessor& storeAccessor) {
uint8_t* tempData = nullptr;
ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_);
storeAccessor.constDataPointer = tempData;
return status;
}
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(
store_address_t packet_id, const uint8_t** packet_ptr, size_t* size) {
@ -153,6 +172,26 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(
return status;
}
template<uint8_t NUMBER_OF_POOLS>
inline AccessorPair LocalPool<NUMBER_OF_POOLS>::modifyData(
store_address_t storeId) {
uint8_t* tempData = nullptr;
StorageAccessor accessor(storeId);
ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_);
accessor.constDataPointer = tempData;
accessor.assignConstPointer();
return AccessorPair(status, std::move(accessor));
}
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
store_address_t storeId, StorageAccessor& storeAccessor) {
ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer,
&storeAccessor.size_);
storeAccessor.assignConstPointer();
return status;
}
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
store_address_t packet_id, uint8_t** packet_ptr, size_t* size) {

View File

@ -1,9 +1,9 @@
#ifndef POOLMANAGER_H_
#define POOLMANAGER_H_
#include <framework/storagemanager/LocalPool.h>
#include <framework/ipc/MutexHelper.h>
#include <framework/storagemanager/StorageAccessor.h>
/**
* @brief The PoolManager class provides an intermediate data storage with
@ -11,20 +11,21 @@
* @details Uses local pool calls but is thread safe by protecting the call
* with a lock.
*/
template <uint8_t NUMBER_OF_POOLS = 5>
template <uint8_t NUMBER_OF_POOLS>
class PoolManager : public LocalPool<NUMBER_OF_POOLS> {
public:
PoolManager( object_id_t setObjectId, const uint16_t element_sizes[NUMBER_OF_POOLS],
const uint16_t n_elements[NUMBER_OF_POOLS] );
/**
* @brief In the PoolManager's destructor all allocated memory is freed.
*/
PoolManager(object_id_t setObjectId,
const uint16_t element_sizes[NUMBER_OF_POOLS],
const uint16_t n_elements[NUMBER_OF_POOLS]);
//! @brief In the PoolManager's destructor all allocated memory is freed.
virtual ~PoolManager();
//! @brief LocalPool overrides for thread-safety. Decorator function 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 = NULL) override;
store_address_t* storeId = nullptr) override;
protected:
ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address,
bool ignoreFault) override;

View File

@ -1,3 +1,6 @@
#ifndef POOLMANAGER_TPP_
#define POOLMANAGER_TPP_
template<uint8_t NUMBER_OF_POOLS>
inline PoolManager<NUMBER_OF_POOLS>::PoolManager(object_id_t setObjectId,
const uint16_t element_sizes[NUMBER_OF_POOLS],
@ -40,3 +43,5 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer,
return status;
}
#endif

View File

@ -4,8 +4,7 @@
* @details These helper can be used together with the
* StorageManager classes to manage access to a storage.
* It can take care of thread-safety while also providing
* mechanisms to automatically clear storage data and unlocking the
* pool.
* mechanisms to automatically clear storage data.
*/
#ifndef TEST_PROTOTYPES_STORAGEACCESSOR_H_
#define TEST_PROTOTYPES_STORAGEACCESSOR_H_
@ -14,7 +13,6 @@
#include <framework/storagemanager/StorageManagerIF.h>
#include <memory>
/**
* @brief Accessor class which can be returned by pool managers
* or passed and set by pool managers to have safe access to the pool

View File

@ -3,7 +3,14 @@
#include <framework/events/Event.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <stddef.h>
#include <cstddef>
#include <utility>
class StorageAccessor;
class ConstStorageAccessor;
using AccessorPair = std::pair<ReturnValue_t, StorageAccessor>;
using ConstAccessorPair = std::pair<ReturnValue_t, ConstStorageAccessor>;
/**
* This union defines the type that identifies where a data packet is
@ -150,6 +157,14 @@ public:
*/
virtual ReturnValue_t getFreeElement(store_address_t* storageId,
const size_t size, uint8_t** p_data, bool ignoreFault = false ) = 0;
virtual AccessorPair modifyData(store_address_t storeId) = 0;
virtual ConstAccessorPair getData(store_address_t storeId) = 0;
virtual ReturnValue_t modifyData(store_address_t storeId,
StorageAccessor&) = 0;
virtual ReturnValue_t getData(store_address_t storeId,
ConstStorageAccessor&) = 0;
/**
* Clears the whole store.
* Use with care!