2020-07-14 15:45:03 +02:00
|
|
|
#include <framework/datapoollocal/LocalDataPoolManager.h>
|
|
|
|
#include <framework/datapoollocal/LocalPoolDataSetBase.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstring>
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
2020-07-14 15:45:03 +02:00
|
|
|
PoolVariableIF** registeredVariablesArray,
|
|
|
|
const size_t maxNumberOfVariables):
|
|
|
|
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
|
|
|
if(hkOwner == nullptr) {
|
|
|
|
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hkManager = hkOwner->getHkManagerHandle();
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
LocalPoolDataSetBase::LocalPoolDataSetBase(object_id_t ownerId,
|
2020-07-14 15:45:03 +02:00
|
|
|
PoolVariableIF** registeredVariablesArray,
|
|
|
|
const size_t maxNumberOfVariables):
|
|
|
|
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
|
|
|
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
|
|
|
ownerId);
|
|
|
|
if(hkOwner == nullptr) {
|
|
|
|
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hkManager = hkOwner->getHkManagerHandle();
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
LocalPoolDataSetBase::~LocalPoolDataSetBase() {
|
2020-07-14 15:45:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
ReturnValue_t LocalPoolDataSetBase::lockDataPool(uint32_t timeoutMs) {
|
2020-07-14 15:45:03 +02:00
|
|
|
MutexIF* mutex = hkManager->getMutexHandle();
|
2020-08-08 12:49:20 +02:00
|
|
|
return mutex->lockMutex(MutexIF::TimeoutType::WAITING, timeoutMs);
|
2020-07-14 15:45:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer,
|
2020-07-14 15:45:03 +02:00
|
|
|
size_t *size, size_t maxSize,
|
|
|
|
SerializeIF::Endianness streamEndianness) const {
|
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
|
|
|
|
uint8_t validityMask[validityMaskSize];
|
|
|
|
uint8_t validBufferIndex = 0;
|
|
|
|
uint8_t validBufferIndexBit = 0;
|
|
|
|
for (uint16_t count = 0; count < fillCount; count++) {
|
|
|
|
if(registeredVariables[count]->isValid()) {
|
|
|
|
// set validity buffer here.
|
|
|
|
this->bitSetter(validityMask + validBufferIndex,
|
|
|
|
validBufferIndexBit);
|
|
|
|
if(validBufferIndexBit == 7) {
|
|
|
|
validBufferIndex ++;
|
|
|
|
validBufferIndexBit = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
validBufferIndexBit ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
|
|
|
streamEndianness);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// copy validity buffer to end
|
|
|
|
std::memcpy(*buffer, validityMask, validityMaskSize);
|
|
|
|
*size += validityMaskSize;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
|
2020-07-14 15:45:03 +02:00
|
|
|
MutexIF* mutex = hkManager->getMutexHandle();
|
|
|
|
return mutex->unlockMutex();
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer,
|
2020-07-14 15:45:03 +02:00
|
|
|
size_t* size, size_t maxSize,
|
|
|
|
SerializeIF::Endianness streamEndianness) const {
|
|
|
|
for (uint16_t count = 0; count < fillCount; count++) {
|
|
|
|
lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId();
|
|
|
|
auto result = SerializeAdapter::serialize(¤tPoolId, buffer,
|
|
|
|
size, maxSize, streamEndianness);
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
sif::warning << "LocalDataSet::serializeLocalPoolIds: Serialization"
|
|
|
|
" error!" << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const {
|
2020-07-14 15:45:03 +02:00
|
|
|
if(position > 7) {
|
|
|
|
sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte |= 1 << shiftNumber;
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:51:31 +02:00
|
|
|
bool LocalPoolDataSetBase::isValid() const {
|
2020-07-14 15:45:03 +02:00
|
|
|
return this->valid;
|
|
|
|
}
|