better naming
This commit is contained in:
parent
f4a60a0323
commit
b6888a8185
@ -5,15 +5,15 @@
|
||||
LocalPool::LocalPool(object_id_t setObjectId, const LocalPoolConfig& poolConfig,
|
||||
bool registered, bool spillsToHigherPools):
|
||||
SystemObject(setObjectId, registered),
|
||||
NUMBER_OF_POOLS(poolConfig.size()),
|
||||
NUMBER_OF_SUBPOOLS(poolConfig.size()),
|
||||
spillsToHigherPools(spillsToHigherPools) {
|
||||
if(NUMBER_OF_POOLS == 0) {
|
||||
if(NUMBER_OF_SUBPOOLS == 0) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPool::LocalPool: Passed pool configuration is "
|
||||
<< " invalid!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
max_pools_t index = 0;
|
||||
max_subpools_t index = 0;
|
||||
for (const auto& currentPoolConfig: poolConfig) {
|
||||
this->numberOfElements[index] = currentPoolConfig.first;
|
||||
this->elementSizes[index] = currentPoolConfig.second;
|
||||
@ -98,7 +98,7 @@ ReturnValue_t LocalPool::modifyData(store_address_t storeId,
|
||||
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) {
|
||||
if (storeId.poolIndex >= NUMBER_OF_SUBPOOLS) {
|
||||
return ILLEGAL_STORAGE_ID;
|
||||
}
|
||||
if ((storeId.packetIndex >= numberOfElements[storeId.poolIndex])) {
|
||||
@ -151,7 +151,7 @@ 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++) {
|
||||
for (uint16_t n = 0; n < NUMBER_OF_SUBPOOLS; n++) {
|
||||
//Not sure if new allocates all stores in order. so better be careful.
|
||||
if ((store[n].data() <= ptr) and
|
||||
(&store[n][numberOfElements[n]*elementSizes[n]] > ptr)) {
|
||||
@ -192,7 +192,7 @@ ReturnValue_t LocalPool::initialize() {
|
||||
}
|
||||
|
||||
//Check if any pool size is large than the maximum allowed.
|
||||
for (uint8_t count = 0; count < NUMBER_OF_POOLS; count++) {
|
||||
for (uint8_t count = 0; count < NUMBER_OF_SUBPOOLS; count++) {
|
||||
if (elementSizes[count] >= STORAGE_FREE) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "LocalPool::initialize: Pool is too large! "
|
||||
@ -263,8 +263,8 @@ void LocalPool::write(store_address_t storeId, const uint8_t *data,
|
||||
sizeLists[storeId.poolIndex][storeId.packetIndex] = size;
|
||||
}
|
||||
|
||||
LocalPool::size_type LocalPool::getPageSize(max_pools_t poolIndex) {
|
||||
if (poolIndex < NUMBER_OF_POOLS) {
|
||||
LocalPool::size_type LocalPool::getPageSize(max_subpools_t poolIndex) {
|
||||
if (poolIndex < NUMBER_OF_SUBPOOLS) {
|
||||
return elementSizes[poolIndex];
|
||||
}
|
||||
else {
|
||||
@ -278,7 +278,7 @@ void LocalPool::setToSpillToHigherPools(bool enable) {
|
||||
|
||||
ReturnValue_t LocalPool::getPoolIndex(size_t packetSize, uint16_t *poolIndex,
|
||||
uint16_t startAtIndex) {
|
||||
for (uint16_t n = startAtIndex; n < NUMBER_OF_POOLS; n++) {
|
||||
for (uint16_t n = startAtIndex; n < NUMBER_OF_SUBPOOLS; n++) {
|
||||
#if FSFW_VERBOSE_PRINTOUT == 2
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::debug << "LocalPool " << getObjectId() << "::getPoolIndex: Pool: "
|
||||
@ -313,7 +313,7 @@ ReturnValue_t LocalPool::findEmpty(n_pool_elem_t poolIndex, uint16_t *element) {
|
||||
size_t LocalPool::getTotalSize(size_t* additionalSize) {
|
||||
size_t totalSize = 0;
|
||||
size_t sizesSize = 0;
|
||||
for(uint8_t idx = 0; idx < NUMBER_OF_POOLS; idx ++) {
|
||||
for(uint8_t idx = 0; idx < NUMBER_OF_SUBPOOLS; idx ++) {
|
||||
totalSize += elementSizes[idx] * numberOfElements[idx];
|
||||
sizesSize += numberOfElements[idx] * sizeof(size_type);
|
||||
}
|
||||
@ -331,7 +331,7 @@ void LocalPool::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {
|
||||
uint16_t reservedHits = 0;
|
||||
uint8_t idx = 0;
|
||||
uint16_t sum = 0;
|
||||
for(; idx < NUMBER_OF_POOLS; idx ++) {
|
||||
for(; idx < NUMBER_OF_SUBPOOLS; idx ++) {
|
||||
for(const auto& size: sizeLists[idx]) {
|
||||
if(size != STORAGE_FREE) {
|
||||
reservedHits++;
|
||||
@ -343,25 +343,25 @@ void LocalPool::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {
|
||||
sum += buffer[idx];
|
||||
reservedHits = 0;
|
||||
}
|
||||
buffer[idx] = sum / NUMBER_OF_POOLS;
|
||||
buffer[idx] = sum / NUMBER_OF_SUBPOOLS;
|
||||
*bytesWritten += 1;
|
||||
}
|
||||
|
||||
|
||||
void LocalPool::clearPool(max_pools_t poolIndex) {
|
||||
if(poolIndex >= NUMBER_OF_POOLS) {
|
||||
void LocalPool::clearSubPool(max_subpools_t subpoolIndex) {
|
||||
if(subpoolIndex >= NUMBER_OF_SUBPOOLS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark the storage as free
|
||||
for(auto& size: sizeLists[poolIndex]) {
|
||||
for(auto& size: sizeLists[subpoolIndex]) {
|
||||
size = STORAGE_FREE;
|
||||
}
|
||||
|
||||
// Set all the page content to 0.
|
||||
std::memset(store[poolIndex].data(), 0, elementSizes[poolIndex]);
|
||||
std::memset(store[subpoolIndex].data(), 0, elementSizes[subpoolIndex]);
|
||||
}
|
||||
|
||||
LocalPool::max_pools_t LocalPool::getNumberOfPools() const {
|
||||
return NUMBER_OF_POOLS;
|
||||
LocalPool::max_subpools_t LocalPool::getNumberOfSubPools() const {
|
||||
return NUMBER_OF_SUBPOOLS;
|
||||
}
|
||||
|
@ -134,15 +134,15 @@ public:
|
||||
void getFillCount(uint8_t* buffer, uint8_t* bytesWritten) override;
|
||||
|
||||
void clearStore() override;
|
||||
void clearPool(max_pools_t poolIndex) override;
|
||||
void clearSubPool(max_subpools_t poolIndex) override;
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
/**
|
||||
* Get number pools. Each pool has pages with a specific bucket size.
|
||||
* Get number sub pools. Each pool has pages with a specific bucket size.
|
||||
* @return
|
||||
*/
|
||||
max_pools_t getNumberOfPools() const override;
|
||||
max_subpools_t getNumberOfSubPools() const override;
|
||||
protected:
|
||||
/**
|
||||
* With this helper method, a free element of @c size is reserved.
|
||||
@ -163,7 +163,7 @@ private:
|
||||
* @details
|
||||
* This must be less than the maximum number of pools (currently 0xff).
|
||||
*/
|
||||
const max_pools_t NUMBER_OF_POOLS;
|
||||
const max_subpools_t NUMBER_OF_SUBPOOLS;
|
||||
|
||||
/**
|
||||
* Indicates that this element is free.
|
||||
@ -177,20 +177,20 @@ private:
|
||||
* must be set in ascending order on construction.
|
||||
*/
|
||||
std::vector<size_type> elementSizes =
|
||||
std::vector<size_type>(NUMBER_OF_POOLS);
|
||||
std::vector<size_type>(NUMBER_OF_SUBPOOLS);
|
||||
/**
|
||||
* @brief n_elements stores the number of elements per pool.
|
||||
* @details These numbers are maintained for internal pool management.
|
||||
*/
|
||||
std::vector<uint16_t> numberOfElements =
|
||||
std::vector<uint16_t>(NUMBER_OF_POOLS);
|
||||
std::vector<uint16_t>(NUMBER_OF_SUBPOOLS);
|
||||
/**
|
||||
* @brief store represents the actual memory pool.
|
||||
* @details It is an array of pointers to memory, which was allocated with
|
||||
* a @c new call on construction.
|
||||
*/
|
||||
std::vector<std::vector<uint8_t>> store =
|
||||
std::vector<std::vector<uint8_t>>(NUMBER_OF_POOLS);
|
||||
std::vector<std::vector<uint8_t>>(NUMBER_OF_SUBPOOLS);
|
||||
|
||||
/**
|
||||
* @brief The size_list attribute stores the size values of every pool element.
|
||||
@ -198,7 +198,7 @@ private:
|
||||
* is also dynamically allocated there.
|
||||
*/
|
||||
std::vector<std::vector<size_type>> sizeLists =
|
||||
std::vector<std::vector<size_type>>(NUMBER_OF_POOLS);
|
||||
std::vector<std::vector<size_type>>(NUMBER_OF_SUBPOOLS);
|
||||
|
||||
//! A variable to determine whether higher n pools are used if
|
||||
//! the store is full.
|
||||
@ -217,7 +217,7 @@ private:
|
||||
* @param pool_index The pool in which to look.
|
||||
* @return Returns the size of an element or 0.
|
||||
*/
|
||||
size_type getPageSize(max_pools_t poolIndex);
|
||||
size_type getPageSize(max_subpools_t poolIndex);
|
||||
|
||||
/**
|
||||
* @brief This helper method looks up a fitting pool for a given size.
|
||||
|
@ -29,7 +29,7 @@ using ConstAccessorPair = std::pair<ReturnValue_t, ConstStorageAccessor>;
|
||||
class StorageManagerIF : public HasReturnvaluesIF {
|
||||
public:
|
||||
using size_type = size_t;
|
||||
using max_pools_t = uint8_t;
|
||||
using max_subpools_t = uint8_t;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::STORAGE_MANAGER_IF; //!< The unique ID for return codes for this interface.
|
||||
static const ReturnValue_t DATA_TOO_LARGE = MAKE_RETURN_CODE(1); //!< This return code indicates that the data to be stored is too large for the store.
|
||||
@ -149,10 +149,10 @@ public:
|
||||
virtual ReturnValue_t modifyData(store_address_t packet_id,
|
||||
uint8_t** packet_ptr, size_t* size) = 0;
|
||||
/**
|
||||
* This method reserves an element of \c size.
|
||||
* This method reserves an element of @c size.
|
||||
*
|
||||
* It returns the packet id of this element as well as a direct pointer to the
|
||||
* data of the element. It must be assured that exactly \c size data is
|
||||
* data of the element. It must be assured that exactly @c size data is
|
||||
* written to p_data!
|
||||
* @param storageId A pointer to the storageId to retrieve.
|
||||
* @param size The size of the space to be reserved.
|
||||
@ -174,7 +174,7 @@ public:
|
||||
* Clears a pool in the store with the given pool index. Use with care!
|
||||
* @param pageIndex
|
||||
*/
|
||||
virtual void clearPool(uint8_t poolIndex) = 0;
|
||||
virtual void clearSubPool(uint8_t poolIndex) = 0;
|
||||
|
||||
/**
|
||||
* Get the fill count of the pool. Each character inside the provided
|
||||
@ -193,7 +193,7 @@ public:
|
||||
* Get number of pools.
|
||||
* @return
|
||||
*/
|
||||
virtual max_pools_t getNumberOfPools() const = 0;
|
||||
virtual max_subpools_t getNumberOfSubPools() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_STORAGEMANAGER_STORAGEMANAGERIF_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user