Local pool public members/functions moved to top
This commit is contained in:
parent
1f4391f56e
commit
c9e4c73bd2
@ -17,10 +17,11 @@ public:
|
|||||||
//We could create a constructor to initialize the fixed array list with data and the known size field
|
//We could create a constructor to initialize the fixed array list with data and the known size field
|
||||||
//so it can be used for serialization too (with SerialFixedArrrayListAdapter)
|
//so it can be used for serialization too (with SerialFixedArrrayListAdapter)
|
||||||
//is this feasible?
|
//is this feasible?
|
||||||
// FixedArrayList(T * data_, count_t count):
|
FixedArrayList(T * data_, count_t count):
|
||||||
// ArrayList<T, count_t>(data, MAX_SIZE) {
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||||
// memcpy(data, data_, count);
|
memcpy(this->data, data_, count);
|
||||||
// }
|
this->size = count;
|
||||||
|
}
|
||||||
|
|
||||||
FixedArrayList(const FixedArrayList& other) :
|
FixedArrayList(const FixedArrayList& other) :
|
||||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||||
|
@ -71,6 +71,11 @@ ReturnValue_t SerialBufferAdapter<T>::deSerialize(const uint8_t** buffer,
|
|||||||
//TODO Ignores Endian flag!
|
//TODO Ignores Endian flag!
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
if(serializeLength){
|
if(serializeLength){
|
||||||
|
// Suggestion (would require removing rest of the block inside this if clause !):
|
||||||
|
//ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian);
|
||||||
|
//if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
// return result;
|
||||||
|
//}
|
||||||
T serializedSize = AutoSerializeAdapter::getSerializedSize(
|
T serializedSize = AutoSerializeAdapter::getSerializedSize(
|
||||||
&bufferLength);
|
&bufferLength);
|
||||||
if((*size - bufferLength - serializedSize) >= 0){
|
if((*size - bufferLength - serializedSize) >= 0){
|
||||||
@ -113,8 +118,9 @@ const uint8_t * SerialBufferAdapter<T>::getConstBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialBufferAdapter<T>::setBuffer(uint8_t * buffer_) {
|
void SerialBufferAdapter<T>::setBuffer(uint8_t * buffer_, T bufferLength_) {
|
||||||
buffer = buffer_;
|
buffer = buffer_;
|
||||||
|
bufferLength = bufferLength_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
|
|
||||||
uint8_t * getBuffer();
|
uint8_t * getBuffer();
|
||||||
const uint8_t * getConstBuffer();
|
const uint8_t * getConstBuffer();
|
||||||
void setBuffer(uint8_t * buffer_);
|
void setBuffer(uint8_t * buffer_, T bufferLength_);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum bufferType {
|
enum bufferType {
|
||||||
|
@ -29,12 +29,18 @@ public:
|
|||||||
* @param bufferLength
|
* @param bufferLength
|
||||||
* @param serializeLength
|
* @param serializeLength
|
||||||
*/
|
*/
|
||||||
SerialBufferAdapter2(BUFFER_TYPE * buffer_, count_t bufferLength_, bool serializeLength_ = false):
|
SerialBufferAdapter2(void * buffer_, count_t bufferLength_, bool serializeLength_ = false):
|
||||||
buffer(buffer_),bufferLength(bufferLength_), serializeLength(serializeLength_) {
|
bufferLength(bufferLength_), serializeLength(serializeLength_) {
|
||||||
determineLengthMultiplier(sizeof(count_t));
|
determineLengthInBytes(sizeof(BUFFER_TYPE));
|
||||||
if(std::is_const<BUFFER_TYPE>::value) {
|
buffer = reinterpret_cast<const uint8_t *>(buffer_);
|
||||||
isConst = true;
|
constBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SerialBufferAdapter2(const void * buffer_, count_t bufferLength_, bool serializeLength_ = false):
|
||||||
|
bufferLength(bufferLength_), serializeLength(serializeLength_) {
|
||||||
|
determineLengthInBytes(sizeof(BUFFER_TYPE));
|
||||||
|
constBuffer = reinterpret_cast<const uint8_t *>(buffer_);
|
||||||
|
buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t serialize(uint8_t ** buffer, uint32_t* size,
|
ReturnValue_t serialize(uint8_t ** buffer, uint32_t* size,
|
||||||
@ -69,9 +75,13 @@ public:
|
|||||||
ReturnValue_t deSerialize(const uint8_t** buffer,
|
ReturnValue_t deSerialize(const uint8_t** buffer,
|
||||||
int32_t* size, bool bigEndian) {
|
int32_t* size, bool bigEndian) {
|
||||||
//TODO Ignores Endian flag!
|
//TODO Ignores Endian flag!
|
||||||
//UPDATE: Endian swapper introduced. Must be tested..
|
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
if(serializeLength){
|
if(serializeLength){
|
||||||
|
// Suggestion (would require removing rest of the block inside this if clause !):
|
||||||
|
//ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian);
|
||||||
|
//if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
// return result;
|
||||||
|
//}
|
||||||
count_t serializedSize = AutoSerializeAdapter::getSerializedSize(
|
count_t serializedSize = AutoSerializeAdapter::getSerializedSize(
|
||||||
&bufferLength);
|
&bufferLength);
|
||||||
if((*size - bufferLength - serializedSize) >= 0){
|
if((*size - bufferLength - serializedSize) >= 0){
|
||||||
@ -83,15 +93,8 @@ public:
|
|||||||
}
|
}
|
||||||
//No Else If, go on with buffer
|
//No Else If, go on with buffer
|
||||||
if (*size - bufferLength >= 0) {
|
if (*size - bufferLength >= 0) {
|
||||||
uint8_t tmp [bufferLength];
|
|
||||||
uint8_t * pTmp = tmp;
|
|
||||||
if (bigEndian) {
|
|
||||||
EndianSwapper::swap<BUFFER_TYPE>(pTmp,*buffer, bufferLength);
|
|
||||||
} else {
|
|
||||||
pTmp = const_cast<uint8_t *>(*buffer);
|
|
||||||
}
|
|
||||||
*size -= bufferLength;
|
*size -= bufferLength;
|
||||||
memcpy(const_cast<void *>(reinterpret_cast<const void*>(this->buffer)), pTmp, bufferLength);
|
memcpy(this->buffer, *buffer, bufferLength);
|
||||||
(*buffer) += bufferLength;
|
(*buffer) += bufferLength;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
} else {
|
} else {
|
||||||
@ -103,24 +106,30 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t * getBuffer() {
|
BUFFER_TYPE * getBuffer() {
|
||||||
return reinterpret_cast<uint8_t *>(buffer);
|
return reinterpret_cast<BUFFER_TYPE *>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBuffer(BUFFER_TYPE * buffer_, count_t bufferLength_, bool serializeLength_ = false) {
|
void setBuffer(void * buffer_, count_t bufferLength_, bool serializeLength_ = false) {
|
||||||
buffer = buffer_;
|
buffer = buffer_;
|
||||||
bufferLength = bufferLength_;
|
bufferLength = bufferLength_;
|
||||||
serializeLength = serializeLength_;
|
serializeLength = serializeLength_;
|
||||||
determineLengthMultiplier(sizeof(count_t));
|
determineLengthInBytes(sizeof(BUFFER_TYPE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setConstBuffer(const void * buffer_, count_t bufferLength_, bool serializeLength_ = false) {
|
||||||
|
constBuffer = buffer_;
|
||||||
|
bufferLength = bufferLength_;
|
||||||
|
serializeLength = serializeLength_;
|
||||||
|
determineLengthInBytes(sizeof(BUFFER_TYPE));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
BUFFER_TYPE * buffer;
|
uint8_t * buffer;
|
||||||
|
const uint8_t * constBuffer;
|
||||||
count_t bufferLength;
|
count_t bufferLength;
|
||||||
bool serializeLength;
|
bool serializeLength;
|
||||||
|
|
||||||
bool isConst = false;
|
void determineLengthInBytes(uint8_t typeSize) {
|
||||||
|
|
||||||
void determineLengthMultiplier(uint8_t typeSize) {
|
|
||||||
switch(typeSize) {
|
switch(typeSize) {
|
||||||
case(2):
|
case(2):
|
||||||
bufferLength *= 2; break;
|
bufferLength *= 2; break;
|
||||||
@ -134,6 +143,4 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* SERIALBUFFERADAPTER2_H_ */
|
#endif /* SERIALBUFFERADAPTER2_H_ */
|
||||||
|
@ -40,6 +40,94 @@ public:
|
|||||||
* @details This must be less than the maximum number of pools (currently 0xff).
|
* @details This must be less than the maximum number of pools (currently 0xff).
|
||||||
*/
|
*/
|
||||||
// static const uint32_t NUMBER_OF_POOLS;
|
// static const uint32_t NUMBER_OF_POOLS;
|
||||||
|
/**
|
||||||
|
* @brief This is the default constructor for a pool manager instance.
|
||||||
|
* @details By passing two arrays of size NUMBER_OF_POOLS, the constructor
|
||||||
|
* allocates memory (with \c new) for store and size_list. These
|
||||||
|
* regions are all set to zero on start up.
|
||||||
|
* @param setObjectId The object identifier to be set. This allows for
|
||||||
|
* multiple instances of LocalPool in the system.
|
||||||
|
* @param element_sizes An array of size NUMBER_OF_POOLS in which the size
|
||||||
|
* of a single element in each pool is determined.
|
||||||
|
* <b>The sizes must be provided in ascending order.
|
||||||
|
* </b>
|
||||||
|
* @param n_elements An array of size NUMBER_OF_POOLS in which the
|
||||||
|
* number of elements for each pool is determined.
|
||||||
|
* The position of these values correspond to those in
|
||||||
|
* element_sizes.
|
||||||
|
* @param registered Register the pool in object manager or not. Default is false (local pool).
|
||||||
|
* @param spillsToHigherPools
|
||||||
|
* A variable to determine whether higher n pools are used if the store is full.
|
||||||
|
*/
|
||||||
|
LocalPool(object_id_t setObjectId,
|
||||||
|
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
||||||
|
const uint16_t n_elements[NUMBER_OF_POOLS],
|
||||||
|
bool registered = false,
|
||||||
|
bool spillsToHigherPools = false);
|
||||||
|
/**
|
||||||
|
* @brief In the LocalPool's destructor all allocated memory is freed.
|
||||||
|
*/
|
||||||
|
virtual ~LocalPool(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add data to local data pool, performs range check
|
||||||
|
* @param storageId [out] Store ID in which the data will be stored
|
||||||
|
* @param data
|
||||||
|
* @param size
|
||||||
|
* @param ignoreFault
|
||||||
|
* @return @c RETURN_OK if write was successful
|
||||||
|
*/
|
||||||
|
ReturnValue_t addData(store_address_t* storageId, const uint8_t * data,
|
||||||
|
uint32_t size, bool ignoreFault = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With this helper method, a free element of \c size is reserved.
|
||||||
|
* @param storageId [out] storeID of the free element
|
||||||
|
* @param size The minimum packet size that shall be reserved.
|
||||||
|
* @param p_data [out] pointer to the pointer of free element
|
||||||
|
* @param ignoreFault
|
||||||
|
* @return Returns the storage identifier within the storage or
|
||||||
|
* StorageManagerIF::INVALID_ADDRESS (in raw).
|
||||||
|
*/
|
||||||
|
ReturnValue_t getFreeElement(store_address_t* storageId,
|
||||||
|
const uint32_t size, uint8_t** p_data, bool ignoreFault = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve data from local pool
|
||||||
|
* @param packet_id
|
||||||
|
* @param packet_ptr
|
||||||
|
* @param size [out] Size of retrieved data
|
||||||
|
* @return @c RETURN_OK if data retrieval was successfull
|
||||||
|
*/
|
||||||
|
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
|
||||||
|
uint32_t* size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify data by supplying a packet pointer and using that packet pointer
|
||||||
|
* to access and modify the pool entry (via *pointer call)
|
||||||
|
* @param packet_id Store ID of data to modify
|
||||||
|
* @param packet_ptr [out] pointer to the pool entry to modify
|
||||||
|
* @param size [out] size of pool entry
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
|
||||||
|
uint32_t* size);
|
||||||
|
virtual ReturnValue_t deleteData(store_address_t);
|
||||||
|
virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size,
|
||||||
|
store_address_t* storeId = NULL);
|
||||||
|
void clearStore();
|
||||||
|
ReturnValue_t initialize();
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* With this helper method, a free element of \c size is reserved.
|
||||||
|
* @param size The minimum packet size that shall be reserved.
|
||||||
|
* @param[out] address Storage ID of the reserved data.
|
||||||
|
* @return - #RETURN_OK on success,
|
||||||
|
* - the return codes of #getPoolIndex or #findEmpty otherwise.
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault);
|
||||||
|
|
||||||
|
InternalErrorReporterIF *internalErrorReporter;
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Indicates that this element is free.
|
* Indicates that this element is free.
|
||||||
@ -121,93 +209,6 @@ private:
|
|||||||
* - #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 pool_index, uint16_t* element);
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* With this helper method, a free element of \c size is reserved.
|
|
||||||
* @param size The minimum packet size that shall be reserved.
|
|
||||||
* @param[out] address Storage ID of the reserved data.
|
|
||||||
* @return - #RETURN_OK on success,
|
|
||||||
* - the return codes of #getPoolIndex or #findEmpty otherwise.
|
|
||||||
*/
|
|
||||||
virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault);
|
|
||||||
|
|
||||||
InternalErrorReporterIF *internalErrorReporter;
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @brief This is the default constructor for a pool manager instance.
|
|
||||||
* @details By passing two arrays of size NUMBER_OF_POOLS, the constructor
|
|
||||||
* allocates memory (with \c new) for store and size_list. These
|
|
||||||
* regions are all set to zero on start up.
|
|
||||||
* @param setObjectId The object identifier to be set. This allows for
|
|
||||||
* multiple instances of LocalPool in the system.
|
|
||||||
* @param element_sizes An array of size NUMBER_OF_POOLS in which the size
|
|
||||||
* of a single element in each pool is determined.
|
|
||||||
* <b>The sizes must be provided in ascending order.
|
|
||||||
* </b>
|
|
||||||
* @param n_elements An array of size NUMBER_OF_POOLS in which the
|
|
||||||
* number of elements for each pool is determined.
|
|
||||||
* The position of these values correspond to those in
|
|
||||||
* element_sizes.
|
|
||||||
* @param registered Register the pool in object manager or not. Default is false (local pool).
|
|
||||||
* @param spillsToHigherPools
|
|
||||||
* A variable to determine whether higher n pools are used if the store is full.
|
|
||||||
*/
|
|
||||||
LocalPool(object_id_t setObjectId,
|
|
||||||
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
|
||||||
const uint16_t n_elements[NUMBER_OF_POOLS],
|
|
||||||
bool registered = false,
|
|
||||||
bool spillsToHigherPools = false);
|
|
||||||
/**
|
|
||||||
* @brief In the LocalPool's destructor all allocated memory is freed.
|
|
||||||
*/
|
|
||||||
virtual ~LocalPool(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add data to local data pool, performs range check
|
|
||||||
* @param storageId [out] Store ID in which the data will be stored
|
|
||||||
* @param data
|
|
||||||
* @param size
|
|
||||||
* @param ignoreFault
|
|
||||||
* @return @c RETURN_OK if write was successful
|
|
||||||
*/
|
|
||||||
ReturnValue_t addData(store_address_t* storageId, const uint8_t * data,
|
|
||||||
uint32_t size, bool ignoreFault = false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* With this helper method, a free element of \c size is reserved.
|
|
||||||
*
|
|
||||||
* @param size The minimum packet size that shall be reserved.
|
|
||||||
* @return Returns the storage identifier within the storage or
|
|
||||||
* StorageManagerIF::INVALID_ADDRESS (in raw).
|
|
||||||
*/
|
|
||||||
ReturnValue_t getFreeElement(store_address_t* storageId,
|
|
||||||
const uint32_t size, uint8_t** p_data, bool ignoreFault = false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve data from local pool
|
|
||||||
* @param packet_id
|
|
||||||
* @param packet_ptr
|
|
||||||
* @param size [out] Size of retrieved data
|
|
||||||
* @return @c RETURN_OK if data retrieval was successfull
|
|
||||||
*/
|
|
||||||
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
|
|
||||||
uint32_t* size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify data by supplying a packet pointer and using that packet pointer
|
|
||||||
* to access and modify the pool entry (via *pointer call)
|
|
||||||
* @param packet_id Store ID of data to modify
|
|
||||||
* @param packet_ptr [out] pointer to the pool entry to modify
|
|
||||||
* @param size [out] size of pool entry
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
|
|
||||||
uint32_t* size);
|
|
||||||
virtual ReturnValue_t deleteData(store_address_t);
|
|
||||||
virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size,
|
|
||||||
store_address_t* storeId = NULL);
|
|
||||||
void clearStore();
|
|
||||||
ReturnValue_t initialize();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
@ -304,7 +305,7 @@ template<uint8_t NUMBER_OF_POOLS>
|
|||||||
inline LocalPool<NUMBER_OF_POOLS>::LocalPool(object_id_t setObjectId,
|
inline LocalPool<NUMBER_OF_POOLS>::LocalPool(object_id_t setObjectId,
|
||||||
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
const uint16_t element_sizes[NUMBER_OF_POOLS],
|
||||||
const uint16_t n_elements[NUMBER_OF_POOLS], bool registered, bool spillsToHigherPools) :
|
const uint16_t n_elements[NUMBER_OF_POOLS], bool registered, bool spillsToHigherPools) :
|
||||||
SystemObject(setObjectId, registered), spillsToHigherPools(spillsToHigherPools), internalErrorReporter(NULL) {
|
SystemObject(setObjectId, registered), internalErrorReporter(NULL), spillsToHigherPools(spillsToHigherPools){
|
||||||
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
|
||||||
this->element_sizes[n] = element_sizes[n];
|
this->element_sizes[n] = element_sizes[n];
|
||||||
this->n_elements[n] = n_elements[n];
|
this->n_elements[n] = n_elements[n];
|
||||||
|
Loading…
Reference in New Issue
Block a user