new templateless pool prototype
This commit is contained in:
parent
ab603abada
commit
7bd536e763
@ -1,5 +1,4 @@
|
|||||||
#include "EventManager.h"
|
#include "EventManager.h"
|
||||||
#include "EventMessage.h"
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
#include "../ipc/MutexFactory.h"
|
#include "../ipc/MutexFactory.h"
|
||||||
@ -15,9 +14,15 @@ const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
|
|||||||
// SHOULDDO: Shouldn't this be in the config folder and passed via ctor?
|
// SHOULDDO: Shouldn't this be in the config folder and passed via ctor?
|
||||||
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
||||||
|
|
||||||
|
const LocalPool::LocalPoolConfig EventManager::poolConfig = {
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(EventMatchTree::Node), 240),
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(EventIdRangeMatcher), 120),
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(ReporterRangeMatcher), 120)
|
||||||
|
};
|
||||||
|
|
||||||
EventManager::EventManager(object_id_t setObjectId) :
|
EventManager::EventManager(object_id_t setObjectId) :
|
||||||
SystemObject(setObjectId),
|
SystemObject(setObjectId),
|
||||||
factoryBackend(0, POOL_SIZES, N_ELEMENTS, false, true) {
|
factoryBackend(0, poolConfig, false, true) {
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
||||||
|
@ -51,7 +51,9 @@ protected:
|
|||||||
MutexIF* mutex = nullptr;
|
MutexIF* mutex = nullptr;
|
||||||
|
|
||||||
static const uint8_t N_POOLS = 3;
|
static const uint8_t N_POOLS = 3;
|
||||||
LocalPool<N_POOLS> factoryBackend;
|
LocalPool factoryBackend;
|
||||||
|
static const LocalPool::LocalPoolConfig poolConfig;
|
||||||
|
|
||||||
static const uint16_t POOL_SIZES[N_POOLS];
|
static const uint16_t POOL_SIZES[N_POOLS];
|
||||||
static const uint16_t N_ELEMENTS[N_POOLS];
|
static const uint16_t N_ELEMENTS[N_POOLS];
|
||||||
|
|
||||||
|
@ -20,9 +20,7 @@ class StorageManagerIF;
|
|||||||
*/
|
*/
|
||||||
class ConstStorageAccessor {
|
class ConstStorageAccessor {
|
||||||
//! StorageManager classes have exclusive access to private variables.
|
//! StorageManager classes have exclusive access to private variables.
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
|
||||||
friend class PoolManager;
|
friend class PoolManager;
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
|
||||||
friend class LocalPool;
|
friend class LocalPool;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
288
storagemanager/LocalPool.cpp
Normal file
288
storagemanager/LocalPool.cpp
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
#include "LocalPool.h"
|
||||||
|
#include <FSFWConfig.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig poolConfig,
|
||||||
|
bool registered, bool spillsToHigherPools):
|
||||||
|
SystemObject(setObjectId), NUMBER_OF_POOLS(poolConfig.size()) {
|
||||||
|
uint16_t index = 0;
|
||||||
|
for (const auto& currentPoolConfig: poolConfig) {
|
||||||
|
this->elementSizes[index] = currentPoolConfig.first;
|
||||||
|
this->numberOfElements[index] = currentPoolConfig.second;
|
||||||
|
store[index] = std::vector<uint8_t>(
|
||||||
|
numberOfElements[index] * elementSizes[index]);
|
||||||
|
sizeLists[index] = std::vector<size_type>(numberOfElements[index]);
|
||||||
|
//TODO checkme
|
||||||
|
for(auto& size: sizeLists[index]) {
|
||||||
|
size = STORAGE_FREE;
|
||||||
|
}
|
||||||
|
// std::memset(sizeLists[index], 0xff,
|
||||||
|
// numberOfElements[index] * sizeof(size_type));
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalPool::~LocalPool(void) {}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::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) {
|
||||||
|
write(*storageId, data, size);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::getData(store_address_t packetId,
|
||||||
|
const uint8_t **packetPtr, size_t *size) {
|
||||||
|
uint8_t* tempData = nullptr;
|
||||||
|
ReturnValue_t status = modifyData(packetId, &tempData, size);
|
||||||
|
*packetPtr = tempData;
|
||||||
|
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);
|
||||||
|
if (status == RETURN_OK) {
|
||||||
|
*pData = &store[storageId->poolIndex][getRawPosition(*storageId)];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*pData = nullptr;
|
||||||
|
}
|
||||||
|
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 = RETURN_FAILED;
|
||||||
|
if (storeId.poolIndex >= NUMBER_OF_POOLS) {
|
||||||
|
return ILLEGAL_STORAGE_ID;
|
||||||
|
}
|
||||||
|
if ((storeId.packetIndex >= numberOfElements[storeId.poolIndex])) {
|
||||||
|
return ILLEGAL_STORAGE_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeLists[storeId.poolIndex][storeId.packetIndex]
|
||||||
|
!= STORAGE_FREE) {
|
||||||
|
uint32_t packetPosition = getRawPosition(storeId);
|
||||||
|
*packetPtr = &store[storeId.poolIndex][packetPosition];
|
||||||
|
*size = sizeLists[storeId.poolIndex][storeId.packetIndex];
|
||||||
|
status = RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
status = DATA_DOES_NOT_EXIST;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::deleteData(store_address_t storeId) {
|
||||||
|
#if FSFW_DEBUGGING == 1
|
||||||
|
sif::debug << "Delete: Pool: " << std::dec << storeId.poolIndex
|
||||||
|
<< " Index: " << storeId.packetIndex << std::endl;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
ReturnValue_t status = RETURN_OK;
|
||||||
|
size_type pageSize = getPageSize(storeId.poolIndex);
|
||||||
|
if ((pageSize != 0) and
|
||||||
|
(storeId.packetIndex < numberOfElements[storeId.poolIndex])) {
|
||||||
|
uint16_t packetPosition = getRawPosition(storeId);
|
||||||
|
uint8_t* ptr = &store[storeId.poolIndex][packetPosition];
|
||||||
|
std::memset(ptr, 0, pageSize);
|
||||||
|
//Set free list
|
||||||
|
sizeLists[storeId.poolIndex][storeId.packetIndex] = STORAGE_FREE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//pool_index or packet_index is too large
|
||||||
|
sif::error << "LocalPool:deleteData failed." << std::endl;
|
||||||
|
status = ILLEGAL_STORAGE_ID;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::deleteData(uint8_t *ptr, size_t size,
|
||||||
|
store_address_t *storeId) {
|
||||||
|
store_address_t localId;
|
||||||
|
ReturnValue_t result = ILLEGAL_ADDRESS;
|
||||||
|
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
||||||
|
//Not sure if new allocates all stores in order. so better be careful.
|
||||||
|
if ((store[n].data() <= ptr) && (&store[n][numberOfElements[n]*elementSizes[n]]) > ptr) {
|
||||||
|
localId.poolIndex = n;
|
||||||
|
uint32_t deltaAddress = ptr - store[n].data();
|
||||||
|
// Getting any data from the right "block" is ok.
|
||||||
|
// This is necessary, as IF's sometimes don't point to the first
|
||||||
|
// element of an object.
|
||||||
|
localId.packetIndex = deltaAddress / elementSizes[n];
|
||||||
|
result = deleteData(localId);
|
||||||
|
#if FSFW_DEBUGGING == 1
|
||||||
|
if (deltaAddress % elementSizes[n] != 0) {
|
||||||
|
sif::error << "LocalPool::deleteData: Address not aligned!"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (storeId != nullptr) {
|
||||||
|
*storeId = localId;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::initialize() {
|
||||||
|
ReturnValue_t result = SystemObject::initialize();
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
|
||||||
|
objects::INTERNAL_ERROR_REPORTER);
|
||||||
|
if (internalErrorReporter == nullptr){
|
||||||
|
return ObjectManagerIF::INTERNAL_ERR_REPORTER_UNINIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if any pool size is large than the maximum allowed.
|
||||||
|
for (uint8_t count = 0; count < NUMBER_OF_POOLS; count++) {
|
||||||
|
if (elementSizes[count] >= STORAGE_FREE) {
|
||||||
|
sif::error << "LocalPool::initialize: Pool is too large! "
|
||||||
|
"Max. allowed size is: " << (STORAGE_FREE - 1) << std::endl;
|
||||||
|
return StorageManagerIF::POOL_TOO_LARGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPool::clearStore() {
|
||||||
|
for(auto& sizeList: sizeLists) {
|
||||||
|
for(auto& size: sizeList) {
|
||||||
|
size = STORAGE_FREE;
|
||||||
|
}
|
||||||
|
// std::memset(sizeList[index], 0xff,
|
||||||
|
// numberOfElements[index] * sizeof(size_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::reserveSpace(const size_t size,
|
||||||
|
store_address_t *storeId, bool ignoreFault) {
|
||||||
|
ReturnValue_t status = getPoolIndex(size, &storeId->poolIndex);
|
||||||
|
if (status != RETURN_OK) {
|
||||||
|
sif::error << "LocalPool( " << std::hex << getObjectId() << std::dec
|
||||||
|
<< " )::reserveSpace: Packet too large." << std::endl;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
status = findEmpty(storeId->poolIndex, &storeId->packetIndex);
|
||||||
|
while (status != RETURN_OK && spillsToHigherPools) {
|
||||||
|
status = getPoolIndex(size, &storeId->poolIndex, storeId->poolIndex + 1);
|
||||||
|
if (status != RETURN_OK) {
|
||||||
|
//We don't find any fitting pool anymore.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
status = findEmpty(storeId->poolIndex, &storeId->packetIndex);
|
||||||
|
}
|
||||||
|
if (status == RETURN_OK) {
|
||||||
|
#if FSFW_DEBUGGING == 1
|
||||||
|
sif::debug << "Reserve: Pool: " << std::dec
|
||||||
|
<< storeId->poolIndex << " Index: " << storeId->packetIndex
|
||||||
|
<< std::endl;
|
||||||
|
#endif
|
||||||
|
sizeLists[storeId->poolIndex][storeId->packetIndex] = size;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ((not ignoreFault) and (internalErrorReporter != nullptr)) {
|
||||||
|
internalErrorReporter->storeFull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalPool::write(store_address_t storeId, const uint8_t *data,
|
||||||
|
size_t size) {
|
||||||
|
uint8_t* ptr = nullptr;
|
||||||
|
size_type packetPosition = getRawPosition(storeId);
|
||||||
|
|
||||||
|
// Size was checked before calling this function.
|
||||||
|
ptr = &store[storeId.poolIndex][packetPosition];
|
||||||
|
std::memcpy(ptr, data, size);
|
||||||
|
sizeLists[storeId.poolIndex][storeId.packetIndex] = size;
|
||||||
|
}
|
||||||
|
LocalPool::size_type LocalPool::getPageSize(uint16_t poolIndex) {
|
||||||
|
if (poolIndex < NUMBER_OF_POOLS) {
|
||||||
|
return elementSizes[poolIndex];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::getPoolIndex(size_t packetSize, uint16_t *poolIndex,
|
||||||
|
uint16_t startAtIndex) {
|
||||||
|
for (uint16_t n = startAtIndex; n < NUMBER_OF_POOLS; n++) {
|
||||||
|
#if FSFW_DEBUGGING == 1
|
||||||
|
sif::debug << "LocalPool " << getObjectId() << "::getPoolIndex: Pool: "
|
||||||
|
<< n << ", Element Size: " << elementSizes[n] << std::endl;
|
||||||
|
#endif
|
||||||
|
if (elementSizes[n] >= packetSize) {
|
||||||
|
*poolIndex = n;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DATA_TOO_LARGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalPool::size_type LocalPool::getRawPosition(store_address_t storeId) {
|
||||||
|
return storeId.packetIndex * elementSizes[storeId.poolIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t LocalPool::findEmpty(uint16_t poolIndex, uint16_t *element) {
|
||||||
|
ReturnValue_t status = DATA_STORAGE_FULL;
|
||||||
|
for (uint16_t foundElement = 0; foundElement < numberOfElements[poolIndex];
|
||||||
|
foundElement++) {
|
||||||
|
if (sizeLists[poolIndex][foundElement] == STORAGE_FREE) {
|
||||||
|
*element = foundElement;
|
||||||
|
status = RETURN_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
@ -7,57 +7,61 @@
|
|||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
#include "../internalError/InternalErrorReporterIF.h"
|
#include "../internalError/InternalErrorReporterIF.h"
|
||||||
#include "../storagemanager/StorageAccessor.h"
|
#include "../storagemanager/StorageAccessor.h"
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <utility>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The LocalPool class provides an intermediate data storage with
|
* @brief The LocalPool class provides an intermediate data storage with
|
||||||
* a fixed pool size policy.
|
* a fixed pool size policy.
|
||||||
* @details The class implements the StorageManagerIF interface. While the
|
* @details The class implements the StorageManagerIF interface. While the
|
||||||
* total number of pools is fixed, the element sizes in one pool and
|
* total number of pools is fixed, the element sizes in one pool and
|
||||||
* the number of pool elements per pool are set on construction.
|
* the number of pool elements per pool are set on construction.
|
||||||
* The full amount of memory is allocated on construction.
|
* The full amount of memory is allocated on construction.
|
||||||
* The overhead is 4 byte per pool element to store the size
|
* The overhead is 4 byte per pool element to store the size
|
||||||
* information of each stored element.
|
* information of each stored element.
|
||||||
* To maintain an "empty" information, the pool size is limited to
|
* To maintain an "empty" information, the pool size is limited to
|
||||||
* 0xFFFF-1 bytes.
|
* 0xFFFF-1 bytes.
|
||||||
* It is possible to store empty packets in the pool.
|
* It is possible to store empty packets in the pool.
|
||||||
* The local pool is NOT thread-safe.
|
* The local pool is NOT thread-safe.
|
||||||
* @author Bastian Baetz
|
|
||||||
*/
|
*/
|
||||||
template<uint8_t NUMBER_OF_POOLS = 5>
|
|
||||||
class LocalPool: public SystemObject, public StorageManagerIF {
|
class LocalPool: public SystemObject, public StorageManagerIF {
|
||||||
public:
|
public:
|
||||||
/**
|
using size_type = size_t;
|
||||||
* @brief This definition generally sets the number of different sized pools.
|
|
||||||
* @details This must be less than the maximum number of pools (currently 0xff).
|
using poolElementSize = size_type;
|
||||||
*/
|
using numberPoolElements = uint16_t;
|
||||||
// static const uint32_t NUMBER_OF_POOLS;
|
using LocalPoolCfgPair = std::pair<poolElementSize, numberPoolElements>;
|
||||||
/**
|
using LocalPoolConfig = std::multiset<LocalPoolCfgPair>;
|
||||||
* @brief This is the default constructor for a pool manager instance.
|
/**
|
||||||
* @details By passing two arrays of size NUMBER_OF_POOLS, the constructor
|
* @brief This definition generally sets the number of different sized pools.
|
||||||
* allocates memory (with @c new) for store and size_list. These
|
* @details This must be less than the maximum number of pools (currently 0xff).
|
||||||
* regions are all set to zero on start up.
|
*/
|
||||||
* @param setObjectId The object identifier to be set. This allows for
|
const uint8_t NUMBER_OF_POOLS;
|
||||||
* multiple instances of LocalPool in the system.
|
/**
|
||||||
* @param element_sizes An array of size NUMBER_OF_POOLS in which the size
|
* @brief This is the default constructor for a pool manager instance.
|
||||||
* of a single element in each pool is determined.
|
* @details By passing two arrays of size NUMBER_OF_POOLS, the constructor
|
||||||
* <b>The sizes must be provided in ascending order.
|
* allocates memory (with @c new) for store and size_list. These
|
||||||
* </b>
|
* regions are all set to zero on start up.
|
||||||
* @param n_elements An array of size NUMBER_OF_POOLS in which the
|
* @param setObjectId The object identifier to be set. This allows for
|
||||||
* number of elements for each pool is determined.
|
* multiple instances of LocalPool in the system.
|
||||||
* The position of these values correspond to those in
|
* @param element_sizes An array of size NUMBER_OF_POOLS in which the size
|
||||||
* element_sizes.
|
* of a single element in each pool is determined.
|
||||||
* @param registered Register the pool in object manager or not.
|
* <b>The sizes must be provided in ascending order.
|
||||||
* Default is false (local pool).
|
* </b>
|
||||||
* @param spillsToHigherPools A variable to determine whether
|
* @param n_elements An array of size NUMBER_OF_POOLS in which the
|
||||||
* higher n pools are used if the store is full.
|
* number of elements for each pool is determined.
|
||||||
*/
|
* The position of these values correspond to those in
|
||||||
LocalPool(object_id_t setObjectId,
|
* element_sizes.
|
||||||
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
* @param registered Register the pool in object manager or not.
|
||||||
const uint16_t n_elements[NUMBER_OF_POOLS],
|
* Default is false (local pool).
|
||||||
bool registered = false,
|
* @param spillsToHigherPools A variable to determine whether
|
||||||
bool spillsToHigherPools = false);
|
* higher n pools are used if the store is full.
|
||||||
|
*/
|
||||||
|
LocalPool(object_id_t setObjectId, const LocalPoolConfig poolConfig,
|
||||||
|
bool registered = false, bool spillsToHigherPools = false);
|
||||||
/**
|
/**
|
||||||
* @brief In the LocalPool's destructor all allocated memory is freed.
|
* @brief In the LocalPool's destructor all allocated memory is freed.
|
||||||
*/
|
*/
|
||||||
@ -66,24 +70,26 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Documentation: See StorageManagerIF.h
|
* Documentation: See StorageManagerIF.h
|
||||||
*/
|
*/
|
||||||
ReturnValue_t addData(store_address_t* storageId, const uint8_t * data,
|
ReturnValue_t addData(store_address_t* storeId, const uint8_t * data,
|
||||||
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* storeId,const size_t size,
|
||||||
uint8_t** p_data, bool ignoreFault = false) override;
|
uint8_t** pData, bool ignoreFault = false) override;
|
||||||
|
|
||||||
ConstAccessorPair getData(store_address_t packet_id) override;
|
ConstAccessorPair getData(store_address_t storeId) override;
|
||||||
ReturnValue_t getData(store_address_t packet_id, ConstStorageAccessor&) override;
|
ReturnValue_t getData(store_address_t storeId,
|
||||||
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
|
ConstStorageAccessor& constAccessor) 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;
|
size_t * size) override;
|
||||||
|
|
||||||
AccessorPair modifyData(store_address_t packet_id) override;
|
virtual ReturnValue_t deleteData(store_address_t storeId) 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,
|
virtual ReturnValue_t deleteData(uint8_t* ptr, size_t size,
|
||||||
store_address_t* storeId = NULL) override;
|
store_address_t* storeId = nullptr) override;
|
||||||
void clearStore() override;
|
void clearStore() override;
|
||||||
ReturnValue_t initialize() override;
|
ReturnValue_t initialize() override;
|
||||||
protected:
|
protected:
|
||||||
@ -94,43 +100,48 @@ protected:
|
|||||||
* @return - #RETURN_OK on success,
|
* @return - #RETURN_OK on success,
|
||||||
* - the return codes of #getPoolIndex or #findEmpty otherwise.
|
* - the return codes of #getPoolIndex or #findEmpty otherwise.
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t reserveSpace(const uint32_t size,
|
virtual ReturnValue_t reserveSpace(const size_t size,
|
||||||
store_address_t* address, bool ignoreFault);
|
store_address_t* address, bool ignoreFault);
|
||||||
|
|
||||||
InternalErrorReporterIF *internalErrorReporter;
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Indicates that this element is free.
|
* Indicates that this element is free.
|
||||||
* This value limits the maximum size of a pool. Change to larger data type
|
* This value limits the maximum size of a pool.
|
||||||
* if increase is required.
|
* Change to larger data type if increase is required.
|
||||||
*/
|
*/
|
||||||
static const uint32_t STORAGE_FREE = 0xFFFFFFFF;
|
static const size_type STORAGE_FREE = std::numeric_limits<size_type>::max();
|
||||||
/**
|
/**
|
||||||
* @brief In this array, the element sizes of each pool is stored.
|
* @brief In this array, the element sizes of each pool is stored.
|
||||||
* @details The sizes are maintained for internal pool management. The sizes
|
* @details The sizes are maintained for internal pool management. The sizes
|
||||||
* must be set in ascending order on construction.
|
* must be set in ascending order on construction.
|
||||||
*/
|
*/
|
||||||
uint32_t element_sizes[NUMBER_OF_POOLS];
|
std::vector<size_type> elementSizes =
|
||||||
|
std::vector<size_type>(NUMBER_OF_POOLS);
|
||||||
/**
|
/**
|
||||||
* @brief n_elements stores the number of elements per pool.
|
* @brief n_elements stores the number of elements per pool.
|
||||||
* @details These numbers are maintained for internal pool management.
|
* @details These numbers are maintained for internal pool management.
|
||||||
*/
|
*/
|
||||||
uint16_t n_elements[NUMBER_OF_POOLS];
|
std::vector<uint16_t> numberOfElements =
|
||||||
|
std::vector<uint16_t>(NUMBER_OF_POOLS);
|
||||||
/**
|
/**
|
||||||
* @brief store represents the actual memory pool.
|
* @brief store represents the actual memory pool.
|
||||||
* @details It is an array of pointers to memory, which was allocated with
|
* @details It is an array of pointers to memory, which was allocated with
|
||||||
* a @c new call on construction.
|
* a @c new call on construction.
|
||||||
*/
|
*/
|
||||||
uint8_t* store[NUMBER_OF_POOLS];
|
std::vector<std::vector<uint8_t>> store =
|
||||||
|
std::vector<std::vector<uint8_t>>(NUMBER_OF_POOLS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The size_list attribute stores the size values of every pool element.
|
* @brief The size_list attribute stores the size values of every pool element.
|
||||||
* @details As the number of elements is determined on construction, the size list
|
* @details As the number of elements is determined on construction, the size list
|
||||||
* is also dynamically allocated there.
|
* is also dynamically allocated there.
|
||||||
*/
|
*/
|
||||||
uint32_t* size_list[NUMBER_OF_POOLS];
|
std::vector<std::vector<size_type>> sizeLists =
|
||||||
|
std::vector<std::vector<size_type>>(NUMBER_OF_POOLS);
|
||||||
|
|
||||||
//! A variable to determine whether higher n pools are used if
|
//! A variable to determine whether higher n pools are used if
|
||||||
//! the store is full.
|
//! the store is full.
|
||||||
bool spillsToHigherPools;
|
bool spillsToHigherPools = false;
|
||||||
/**
|
/**
|
||||||
* @brief This method safely stores the given data in the given packet_id.
|
* @brief This method safely stores the given data in the given packet_id.
|
||||||
* @details It also sets the size in size_list. The method does not perform
|
* @details It also sets the size in size_list. The method does not perform
|
||||||
@ -139,13 +150,13 @@ private:
|
|||||||
* @param data The data to be stored.
|
* @param data The data to be stored.
|
||||||
* @param size The size of the data to be stored.
|
* @param size The size of the data to be stored.
|
||||||
*/
|
*/
|
||||||
void write(store_address_t packet_id, const uint8_t* data, size_t size);
|
void write(store_address_t packetId, const uint8_t* data, size_t size);
|
||||||
/**
|
/**
|
||||||
* @brief A helper method to read the element size of a certain pool.
|
* @brief A helper method to read the element size of a certain pool.
|
||||||
* @param pool_index The pool in which to look.
|
* @param pool_index The pool in which to look.
|
||||||
* @return Returns the size of an element or 0.
|
* @return Returns the size of an element or 0.
|
||||||
*/
|
*/
|
||||||
uint32_t getPageSize(uint16_t pool_index);
|
size_type getPageSize(uint16_t poolIndex);
|
||||||
/**
|
/**
|
||||||
* @brief This helper method looks up a fitting pool for a given size.
|
* @brief This helper method looks up a fitting pool for a given size.
|
||||||
* @details The pools are looked up in ascending order, so the first that
|
* @details The pools are looked up in ascending order, so the first that
|
||||||
@ -162,7 +173,7 @@ private:
|
|||||||
* @return - #RETURN_OK on success,
|
* @return - #RETURN_OK on success,
|
||||||
* - #DATA_TOO_LARGE otherwise.
|
* - #DATA_TOO_LARGE otherwise.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t getPoolIndex(size_t packet_size, uint16_t* poolIndex,
|
ReturnValue_t getPoolIndex(size_t packetSize, uint16_t* poolIndex,
|
||||||
uint16_t startAtIndex = 0);
|
uint16_t startAtIndex = 0);
|
||||||
/**
|
/**
|
||||||
* @brief This helper method calculates the true array position in store
|
* @brief This helper method calculates the true array position in store
|
||||||
@ -172,7 +183,7 @@ private:
|
|||||||
* @param packet_id The packet id to look up.
|
* @param packet_id The packet id to look up.
|
||||||
* @return Returns the position of the data in store.
|
* @return Returns the position of the data in store.
|
||||||
*/
|
*/
|
||||||
uint32_t getRawPosition(store_address_t packet_id);
|
size_type getRawPosition(store_address_t storeId);
|
||||||
/**
|
/**
|
||||||
* @brief This is a helper method to find an empty element in a given pool.
|
* @brief This is a helper method to find an empty element in a given pool.
|
||||||
* @details The method searches size_list for the first empty element, so
|
* @details The method searches size_list for the first empty element, so
|
||||||
@ -182,9 +193,9 @@ private:
|
|||||||
* @return - #RETURN_OK on success,
|
* @return - #RETURN_OK on success,
|
||||||
* - #DATA_STORAGE_FULL if the store is full
|
* - #DATA_STORAGE_FULL if the store is full
|
||||||
*/
|
*/
|
||||||
ReturnValue_t findEmpty(uint16_t pool_index, uint16_t* element);
|
ReturnValue_t findEmpty(uint16_t poolIndex, uint16_t* element);
|
||||||
|
|
||||||
|
InternalErrorReporterIF *internalErrorReporter = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "LocalPool.tpp"
|
|
||||||
|
|
||||||
#endif /* FSFW_STORAGEMANAGER_LOCALPOOL_H_ */
|
#endif /* FSFW_STORAGEMANAGER_LOCALPOOL_H_ */
|
||||||
|
51
storagemanager/PoolManager.cpp
Normal file
51
storagemanager/PoolManager.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "PoolManager.h"
|
||||||
|
#include <FSFWConfig.h>
|
||||||
|
|
||||||
|
PoolManager::PoolManager(object_id_t setObjectId,
|
||||||
|
const LocalPoolConfig localPoolConfig):
|
||||||
|
LocalPool(setObjectId, localPoolConfig, true) {
|
||||||
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PoolManager::~PoolManager(void) {
|
||||||
|
MutexFactory::instance()->deleteMutex(mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t PoolManager::reserveSpace(const size_t size,
|
||||||
|
store_address_t* address, bool ignoreFault) {
|
||||||
|
MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
|
||||||
|
mutexTimeoutMs);
|
||||||
|
ReturnValue_t status = LocalPool::reserveSpace(size,
|
||||||
|
address,ignoreFault);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t PoolManager::deleteData(
|
||||||
|
store_address_t storeId) {
|
||||||
|
#if FSFW_DEBUGGING == 1
|
||||||
|
sif::debug << "PoolManager( " << translateObject(getObjectId()) <<
|
||||||
|
" )::deleteData from store " << storeId.poolIndex <<
|
||||||
|
". id is "<< storeId.packetIndex << std::endl;
|
||||||
|
#endif
|
||||||
|
MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING,
|
||||||
|
mutexTimeoutMs);
|
||||||
|
return LocalPool::deleteData(storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t PoolManager::deleteData(uint8_t* buffer,
|
||||||
|
size_t size, store_address_t* storeId) {
|
||||||
|
MutexHelper mutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
|
ReturnValue_t status = LocalPool::deleteData(buffer,
|
||||||
|
size, storeId);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PoolManager::setMutexTimeout(
|
||||||
|
uint32_t mutexTimeoutMs) {
|
||||||
|
this->mutexTimeoutMs = mutexTimeoutMs;
|
||||||
|
}
|
@ -13,12 +13,9 @@
|
|||||||
* with a lock.
|
* with a lock.
|
||||||
* @author Bastian Baetz
|
* @author Bastian Baetz
|
||||||
*/
|
*/
|
||||||
template <uint8_t NUMBER_OF_POOLS = 5>
|
class PoolManager: public LocalPool {
|
||||||
class PoolManager : public LocalPool<NUMBER_OF_POOLS> {
|
|
||||||
public:
|
public:
|
||||||
PoolManager(object_id_t setObjectId,
|
PoolManager(object_id_t setObjectId, const LocalPoolConfig poolConfig);
|
||||||
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
|
* @brief In the PoolManager's destructor all allocated memory
|
||||||
@ -39,7 +36,7 @@ protected:
|
|||||||
//! Default mutex timeout value to prevent permanent blocking.
|
//! Default mutex timeout value to prevent permanent blocking.
|
||||||
uint32_t mutexTimeoutMs = 20;
|
uint32_t mutexTimeoutMs = 20;
|
||||||
|
|
||||||
ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address,
|
ReturnValue_t reserveSpace(const size_t size, store_address_t* address,
|
||||||
bool ignoreFault) override;
|
bool ignoreFault) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,6 +48,4 @@ protected:
|
|||||||
MutexIF* mutex;
|
MutexIF* mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "PoolManager.tpp"
|
|
||||||
|
|
||||||
#endif /* FSFW_STORAGEMANAGER_POOLMANAGER_H_ */
|
#endif /* FSFW_STORAGEMANAGER_POOLMANAGER_H_ */
|
||||||
|
@ -10,9 +10,7 @@ class StorageManagerIF;
|
|||||||
*/
|
*/
|
||||||
class StorageAccessor: public ConstStorageAccessor {
|
class StorageAccessor: public ConstStorageAccessor {
|
||||||
//! StorageManager classes have exclusive access to private variables.
|
//! StorageManager classes have exclusive access to private variables.
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
|
||||||
friend class PoolManager;
|
friend class PoolManager;
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
|
||||||
friend class LocalPool;
|
friend class LocalPool;
|
||||||
public:
|
public:
|
||||||
StorageAccessor(store_address_t storeId);
|
StorageAccessor(store_address_t storeId);
|
||||||
|
@ -33,7 +33,7 @@ union store_address_t {
|
|||||||
* @param packetIndex
|
* @param packetIndex
|
||||||
*/
|
*/
|
||||||
store_address_t(uint16_t poolIndex, uint16_t packetIndex):
|
store_address_t(uint16_t poolIndex, uint16_t packetIndex):
|
||||||
pool_index(poolIndex),packet_index(packetIndex){}
|
poolIndex(poolIndex), packetIndex(packetIndex){}
|
||||||
/**
|
/**
|
||||||
* A structure with two elements to access the store address pool-like.
|
* A structure with two elements to access the store address pool-like.
|
||||||
*/
|
*/
|
||||||
@ -41,11 +41,11 @@ union store_address_t {
|
|||||||
/**
|
/**
|
||||||
* The index in which pool the packet lies.
|
* The index in which pool the packet lies.
|
||||||
*/
|
*/
|
||||||
uint16_t pool_index;
|
uint16_t poolIndex;
|
||||||
/**
|
/**
|
||||||
* The position in the chosen pool.
|
* The position in the chosen pool.
|
||||||
*/
|
*/
|
||||||
uint16_t packet_index;
|
uint16_t packetIndex;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Alternative access to the raw value.
|
* Alternative access to the raw value.
|
||||||
|
@ -1,21 +1,37 @@
|
|||||||
#include "../../tmtcpacket/packetmatcher/ApidMatcher.h"
|
#include "ApidMatcher.h"
|
||||||
#include "../../tmtcpacket/packetmatcher/PacketMatchTree.h"
|
#include "PacketMatchTree.h"
|
||||||
#include "../../tmtcpacket/packetmatcher/ServiceMatcher.h"
|
#include "ServiceMatcher.h"
|
||||||
#include "../../tmtcpacket/packetmatcher/SubserviceMatcher.h"
|
#include "SubserviceMatcher.h"
|
||||||
|
|
||||||
|
const uint16_t PacketMatchTree::POOL_SIZES[N_POOLS] = { sizeof(ServiceMatcher),
|
||||||
|
sizeof(SubServiceMatcher), sizeof(ApidMatcher),
|
||||||
|
sizeof(PacketMatchTree::Node) };
|
||||||
|
//Maximum number of types and subtypes to filter should be more than sufficient.
|
||||||
|
const uint16_t PacketMatchTree::N_ELEMENTS[N_POOLS] = { 10, 20, 2, 40 };
|
||||||
|
|
||||||
|
const LocalPool::LocalPoolConfig PacketMatchTree::poolConfig = {
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(ServiceMatcher), 10),
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(SubServiceMatcher), 20),
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(ApidMatcher), 2),
|
||||||
|
LocalPool::LocalPoolCfgPair(sizeof(PacketMatchTree::Node), 40)
|
||||||
|
};
|
||||||
|
|
||||||
PacketMatchTree::PacketMatchTree(Node* root) :
|
PacketMatchTree::PacketMatchTree(Node* root) :
|
||||||
MatchTree<TmPacketMinimal*>(root, 2), factoryBackend(0, POOL_SIZES,
|
MatchTree<TmPacketMinimal*>(root, 2),
|
||||||
N_ELEMENTS, false, true), factory(&factoryBackend) {
|
factoryBackend(0, poolConfig, false, true),
|
||||||
|
factory(&factoryBackend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketMatchTree::PacketMatchTree(iterator root) :
|
PacketMatchTree::PacketMatchTree(iterator root) :
|
||||||
MatchTree<TmPacketMinimal*>(root.element, 2), factoryBackend(0,
|
MatchTree<TmPacketMinimal*>(root.element, 2),
|
||||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
factoryBackend(0, poolConfig, false, true),
|
||||||
|
factory(&factoryBackend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketMatchTree::PacketMatchTree() :
|
PacketMatchTree::PacketMatchTree() :
|
||||||
MatchTree<TmPacketMinimal*>((Node*) NULL, 2), factoryBackend(0,
|
MatchTree<TmPacketMinimal*>((Node*) NULL, 2),
|
||||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
factoryBackend(0, poolConfig, false, true),
|
||||||
|
factory(&factoryBackend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketMatchTree::~PacketMatchTree() {
|
PacketMatchTree::~PacketMatchTree() {
|
||||||
@ -172,11 +188,6 @@ ReturnValue_t PacketMatchTree::initialize() {
|
|||||||
return factoryBackend.initialize();
|
return factoryBackend.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint16_t PacketMatchTree::POOL_SIZES[N_POOLS] = { sizeof(ServiceMatcher),
|
|
||||||
sizeof(SubServiceMatcher), sizeof(ApidMatcher),
|
|
||||||
sizeof(PacketMatchTree::Node) };
|
|
||||||
//Maximum number of types and subtypes to filter should be more than sufficient.
|
|
||||||
const uint16_t PacketMatchTree::N_ELEMENTS[N_POOLS] = { 10, 20, 2, 40 };
|
|
||||||
|
|
||||||
ReturnValue_t PacketMatchTree::changeMatch(bool addToMatch, uint16_t apid,
|
ReturnValue_t PacketMatchTree::changeMatch(bool addToMatch, uint16_t apid,
|
||||||
uint8_t type, uint8_t subtype) {
|
uint8_t type, uint8_t subtype) {
|
||||||
|
@ -23,8 +23,9 @@ protected:
|
|||||||
ReturnValue_t cleanUpElement(iterator position);
|
ReturnValue_t cleanUpElement(iterator position);
|
||||||
private:
|
private:
|
||||||
static const uint8_t N_POOLS = 4;
|
static const uint8_t N_POOLS = 4;
|
||||||
LocalPool<N_POOLS> factoryBackend;
|
LocalPool factoryBackend;
|
||||||
PlacementFactory factory;
|
PlacementFactory factory;
|
||||||
|
static const LocalPool::LocalPoolConfig poolConfig;
|
||||||
static const uint16_t POOL_SIZES[N_POOLS];
|
static const uint16_t POOL_SIZES[N_POOLS];
|
||||||
static const uint16_t N_ELEMENTS[N_POOLS];
|
static const uint16_t N_ELEMENTS[N_POOLS];
|
||||||
template<typename VALUE_T, typename INSERTION_T>
|
template<typename VALUE_T, typename INSERTION_T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user