WIP: somethings wrong.. #19
@ -6,7 +6,8 @@
|
|||||||
#include <framework/storagemanager/StorageManagerIF.h>
|
#include <framework/storagemanager/StorageManagerIF.h>
|
||||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||||
#include <framework/internalError/InternalErrorReporterIF.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
|
* @brief The LocalPool class provides an intermediate data storage with
|
||||||
@ -67,10 +68,17 @@ public:
|
|||||||
size_t size, bool ignoreFault = false) override;
|
size_t size, bool ignoreFault = false) override;
|
||||||
ReturnValue_t getFreeElement(store_address_t* storageId,const size_t size,
|
ReturnValue_t getFreeElement(store_address_t* storageId,const size_t size,
|
||||||
uint8_t** p_data, bool ignoreFault = false) override;
|
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,
|
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
|
||||||
size_t * size) override;
|
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,
|
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
|
||||||
size_t * size) override;
|
size_t * size) override;
|
||||||
|
|
||||||
virtual ReturnValue_t deleteData(store_address_t) override;
|
virtual ReturnValue_t deleteData(store_address_t) override;
|
||||||
virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size,
|
virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size,
|
||||||
store_address_t* storeId = NULL) override;
|
store_address_t* storeId = NULL) override;
|
||||||
|
@ -121,8 +121,8 @@ inline LocalPool<NUMBER_OF_POOLS>::~LocalPool(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS> inline
|
||||||
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::addData(store_address_t* storageId,
|
ReturnValue_t LocalPool<NUMBER_OF_POOLS>::addData(store_address_t* storageId,
|
||||||
const uint8_t* data, size_t size, bool ignoreFault) {
|
const uint8_t* data, size_t size, bool ignoreFault) {
|
||||||
ReturnValue_t status = reserveSpace(size, storageId, ignoreFault);
|
ReturnValue_t status = reserveSpace(size, storageId, ignoreFault);
|
||||||
if (status == RETURN_OK) {
|
if (status == RETURN_OK) {
|
||||||
@ -144,6 +144,25 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getFreeElement(
|
|||||||
return status;
|
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>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(
|
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(
|
||||||
store_address_t packet_id, const uint8_t** packet_ptr, size_t* size) {
|
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;
|
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>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
|
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
|
||||||
store_address_t packet_id, uint8_t** packet_ptr, size_t* size) {
|
store_address_t packet_id, uint8_t** packet_ptr, size_t* size) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#ifndef POOLMANAGER_H_
|
#ifndef POOLMANAGER_H_
|
||||||
#define POOLMANAGER_H_
|
#define POOLMANAGER_H_
|
||||||
|
|
||||||
|
|
||||||
#include <framework/storagemanager/LocalPool.h>
|
#include <framework/storagemanager/LocalPool.h>
|
||||||
#include <framework/ipc/MutexHelper.h>
|
#include <framework/ipc/MutexHelper.h>
|
||||||
|
#include <framework/storagemanager/StorageAccessor.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The PoolManager class provides an intermediate data storage with
|
* @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
|
* @details Uses local pool calls but is thread safe by protecting the call
|
||||||
* with a lock.
|
* with a lock.
|
||||||
*/
|
*/
|
||||||
|
template <uint8_t NUMBER_OF_POOLS>
|
||||||
template <uint8_t NUMBER_OF_POOLS = 5>
|
|
||||||
class PoolManager : public LocalPool<NUMBER_OF_POOLS> {
|
class PoolManager : public LocalPool<NUMBER_OF_POOLS> {
|
||||||
public:
|
public:
|
||||||
PoolManager( object_id_t setObjectId, const uint16_t element_sizes[NUMBER_OF_POOLS],
|
PoolManager(object_id_t setObjectId,
|
||||||
const uint16_t n_elements[NUMBER_OF_POOLS] );
|
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.
|
|
||||||
*/
|
//! @brief In the PoolManager's destructor all allocated memory is freed.
|
||||||
virtual ~PoolManager();
|
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(store_address_t) override;
|
||||||
ReturnValue_t deleteData(uint8_t* buffer, size_t size,
|
ReturnValue_t deleteData(uint8_t* buffer, size_t size,
|
||||||
store_address_t* storeId = NULL) override;
|
store_address_t* storeId = nullptr) override;
|
||||||
protected:
|
protected:
|
||||||
ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address,
|
ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address,
|
||||||
bool ignoreFault) override;
|
bool ignoreFault) override;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef POOLMANAGER_TPP_
|
||||||
|
#define POOLMANAGER_TPP_
|
||||||
|
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline PoolManager<NUMBER_OF_POOLS>::PoolManager(object_id_t setObjectId,
|
inline PoolManager<NUMBER_OF_POOLS>::PoolManager(object_id_t setObjectId,
|
||||||
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
* @details These helper can be used together with the
|
* @details These helper can be used together with the
|
||||||
* StorageManager classes to manage access to a storage.
|
* StorageManager classes to manage access to a storage.
|
||||||
* It can take care of thread-safety while also providing
|
* It can take care of thread-safety while also providing
|
||||||
* mechanisms to automatically clear storage data and unlocking the
|
* mechanisms to automatically clear storage data.
|
||||||
* pool.
|
|
||||||
*/
|
*/
|
||||||
#ifndef TEST_PROTOTYPES_STORAGEACCESSOR_H_
|
#ifndef TEST_PROTOTYPES_STORAGEACCESSOR_H_
|
||||||
#define TEST_PROTOTYPES_STORAGEACCESSOR_H_
|
#define TEST_PROTOTYPES_STORAGEACCESSOR_H_
|
||||||
@ -14,7 +13,6 @@
|
|||||||
#include <framework/storagemanager/StorageManagerIF.h>
|
#include <framework/storagemanager/StorageManagerIF.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Accessor class which can be returned by pool managers
|
* @brief Accessor class which can be returned by pool managers
|
||||||
* or passed and set by pool managers to have safe access to the pool
|
* or passed and set by pool managers to have safe access to the pool
|
||||||
|
@ -3,7 +3,14 @@
|
|||||||
|
|
||||||
#include <framework/events/Event.h>
|
#include <framework/events/Event.h>
|
||||||
#include <framework/returnvalues/HasReturnvaluesIF.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
|
* 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,
|
virtual ReturnValue_t getFreeElement(store_address_t* storageId,
|
||||||
const size_t size, uint8_t** p_data, bool ignoreFault = false ) = 0;
|
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.
|
* Clears the whole store.
|
||||||
* Use with care!
|
* Use with care!
|
||||||
|
Loading…
Reference in New Issue
Block a user