new attorney for ReadCommitIF
This commit is contained in:
parent
fcff06c83f
commit
a65211be51
@ -1,5 +1,8 @@
|
|||||||
#include "PoolDataSetBase.h"
|
#include "PoolDataSetBase.h"
|
||||||
|
#include "ReadCommitIFAttorney.h"
|
||||||
|
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray,
|
||||||
@ -12,61 +15,61 @@ PoolDataSetBase::~PoolDataSetBase() {}
|
|||||||
|
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::registerVariable(
|
ReturnValue_t PoolDataSetBase::registerVariable(
|
||||||
PoolVariableIF *variable) {
|
PoolVariableIF *variable) {
|
||||||
if (state != States::STATE_SET_UNINITIALISED) {
|
if (state != States::STATE_SET_UNINITIALISED) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "DataSet::registerVariable: "
|
sif::error << "DataSet::registerVariable: "
|
||||||
"Call made in wrong position." << std::endl;
|
"Call made in wrong position." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return DataSetIF::DATA_SET_UNINITIALISED;
|
return DataSetIF::DATA_SET_UNINITIALISED;
|
||||||
}
|
}
|
||||||
if (variable == nullptr) {
|
if (variable == nullptr) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "DataSet::registerVariable: "
|
sif::error << "DataSet::registerVariable: "
|
||||||
"Pool variable is nullptr." << std::endl;
|
"Pool variable is nullptr." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return DataSetIF::POOL_VAR_NULL;
|
return DataSetIF::POOL_VAR_NULL;
|
||||||
}
|
}
|
||||||
if (fillCount >= maxFillCount) {
|
if (fillCount >= maxFillCount) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "DataSet::registerVariable: "
|
sif::error << "DataSet::registerVariable: "
|
||||||
"DataSet is full." << std::endl;
|
"DataSet is full." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return DataSetIF::DATA_SET_FULL;
|
return DataSetIF::DATA_SET_FULL;
|
||||||
}
|
}
|
||||||
registeredVariables[fillCount] = variable;
|
registeredVariables[fillCount] = variable;
|
||||||
fillCount++;
|
fillCount++;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::read(MutexIF::TimeoutType timeoutType,
|
ReturnValue_t PoolDataSetBase::read(MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t lockTimeout) {
|
uint32_t lockTimeout) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
ReturnValue_t error = result;
|
ReturnValue_t error = result;
|
||||||
if (state == States::STATE_SET_UNINITIALISED) {
|
if (state == States::STATE_SET_UNINITIALISED) {
|
||||||
lockDataPool(timeoutType, lockTimeout);
|
lockDataPool(timeoutType, lockTimeout);
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
result = readVariable(count);
|
result = readVariable(count);
|
||||||
if(result != RETURN_OK) {
|
if(result != RETURN_OK) {
|
||||||
error = result;
|
error = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state = States::STATE_SET_WAS_READ;
|
state = States::STATE_SET_WAS_READ;
|
||||||
unlockDataPool();
|
unlockDataPool();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "DataSet::read(): "
|
sif::error << "DataSet::read(): "
|
||||||
"Call made in wrong position. Don't forget to commit"
|
"Call made in wrong position. Don't forget to commit"
|
||||||
" member datasets!" << std::endl;
|
" member datasets!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
result = SET_WAS_ALREADY_READ;
|
result = SET_WAS_ALREADY_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(error != HasReturnvaluesIF::RETURN_OK) {
|
if(error != HasReturnvaluesIF::RETURN_OK) {
|
||||||
result = error;
|
result = error;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t PoolDataSetBase::getFillCount() const {
|
uint16_t PoolDataSetBase::getFillCount() const {
|
||||||
@ -74,144 +77,144 @@ uint16_t PoolDataSetBase::getFillCount() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::readVariable(uint16_t count) {
|
ReturnValue_t PoolDataSetBase::readVariable(uint16_t count) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
if(registeredVariables[count] == nullptr) {
|
if(registeredVariables[count] == nullptr) {
|
||||||
// configuration error.
|
/* Configuration error. */
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These checks are often performed by the respective
|
/* These checks are often performed by the respective variable implementation too, but I guess
|
||||||
// variable implementation too, but I guess a double check does not hurt.
|
a double check does not hurt. */
|
||||||
if (registeredVariables[count]->getReadWriteMode() !=
|
if (registeredVariables[count]->getReadWriteMode() !=
|
||||||
PoolVariableIF::VAR_WRITE and
|
PoolVariableIF::VAR_WRITE and
|
||||||
registeredVariables[count]->getDataPoolId()
|
registeredVariables[count]->getDataPoolId()
|
||||||
!= PoolVariableIF::NO_PARAMETER)
|
!= PoolVariableIF::NO_PARAMETER)
|
||||||
{
|
{
|
||||||
if(protectEveryReadCommitCall) {
|
if(protectEveryReadCommitCall) {
|
||||||
result = registeredVariables[count]->read(
|
result = registeredVariables[count]->read(
|
||||||
timeoutTypeForSingleVars,
|
timeoutTypeForSingleVars,
|
||||||
mutexTimeoutForSingleVars);
|
mutexTimeoutForSingleVars);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = registeredVariables[count]->readWithoutLock();
|
result = ReadCommitIFAttorney::readWithoutLock(registeredVariables[count]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
result = INVALID_PARAMETER_DEFINITION;
|
result = INVALID_PARAMETER_DEFINITION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::commit(MutexIF::TimeoutType timeoutType,
|
ReturnValue_t PoolDataSetBase::commit(MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t lockTimeout) {
|
uint32_t lockTimeout) {
|
||||||
if (state == States::STATE_SET_WAS_READ) {
|
if (state == States::STATE_SET_WAS_READ) {
|
||||||
handleAlreadyReadDatasetCommit(timeoutType, lockTimeout);
|
handleAlreadyReadDatasetCommit(timeoutType, lockTimeout);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return handleUnreadDatasetCommit(timeoutType, lockTimeout);
|
return handleUnreadDatasetCommit(timeoutType, lockTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolDataSetBase::handleAlreadyReadDatasetCommit(
|
void PoolDataSetBase::handleAlreadyReadDatasetCommit(
|
||||||
MutexIF::TimeoutType timeoutType, uint32_t lockTimeout) {
|
MutexIF::TimeoutType timeoutType, uint32_t lockTimeout) {
|
||||||
lockDataPool(timeoutType, lockTimeout);
|
lockDataPool(timeoutType, lockTimeout);
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
if (registeredVariables[count]->getReadWriteMode()
|
if (registeredVariables[count]->getReadWriteMode()
|
||||||
!= PoolVariableIF::VAR_READ
|
!= PoolVariableIF::VAR_READ
|
||||||
&& registeredVariables[count]->getDataPoolId()
|
&& registeredVariables[count]->getDataPoolId()
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
if(protectEveryReadCommitCall) {
|
if(protectEveryReadCommitCall) {
|
||||||
registeredVariables[count]->commit(
|
registeredVariables[count]->commit(
|
||||||
timeoutTypeForSingleVars,
|
timeoutTypeForSingleVars,
|
||||||
mutexTimeoutForSingleVars);
|
mutexTimeoutForSingleVars);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
registeredVariables[count]->commitWithoutLock();
|
ReadCommitIFAttorney::commitWithoutLock(registeredVariables[count]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state = States::STATE_SET_UNINITIALISED;
|
state = States::STATE_SET_UNINITIALISED;
|
||||||
unlockDataPool();
|
unlockDataPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::handleUnreadDatasetCommit(
|
ReturnValue_t PoolDataSetBase::handleUnreadDatasetCommit(
|
||||||
MutexIF::TimeoutType timeoutType, uint32_t lockTimeout) {
|
MutexIF::TimeoutType timeoutType, uint32_t lockTimeout) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
lockDataPool(timeoutType, lockTimeout);
|
lockDataPool(timeoutType, lockTimeout);
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
if (registeredVariables[count]->getReadWriteMode()
|
if (registeredVariables[count]->getReadWriteMode()
|
||||||
== PoolVariableIF::VAR_WRITE
|
== PoolVariableIF::VAR_WRITE
|
||||||
&& registeredVariables[count]->getDataPoolId()
|
&& registeredVariables[count]->getDataPoolId()
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
if(protectEveryReadCommitCall) {
|
if(protectEveryReadCommitCall) {
|
||||||
result = registeredVariables[count]->commit(
|
result = registeredVariables[count]->commit(
|
||||||
timeoutTypeForSingleVars,
|
timeoutTypeForSingleVars,
|
||||||
mutexTimeoutForSingleVars);
|
mutexTimeoutForSingleVars);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = registeredVariables[count]->commitWithoutLock();
|
result = registeredVariables[count]->commitWithoutLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (registeredVariables[count]->getDataPoolId()
|
} else if (registeredVariables[count]->getDataPoolId()
|
||||||
!= PoolVariableIF::NO_PARAMETER) {
|
!= PoolVariableIF::NO_PARAMETER) {
|
||||||
if (result != COMMITING_WITHOUT_READING) {
|
if (result != COMMITING_WITHOUT_READING) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "DataSet::commit(): commit-without-read call made "
|
sif::error << "DataSet::commit(): commit-without-read call made "
|
||||||
"with non write-only variable." << std::endl;
|
"with non write-only variable." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
result = COMMITING_WITHOUT_READING;
|
result = COMMITING_WITHOUT_READING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state = States::STATE_SET_UNINITIALISED;
|
state = States::STATE_SET_UNINITIALISED;
|
||||||
unlockDataPool();
|
unlockDataPool();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::lockDataPool(MutexIF::TimeoutType timeoutType,
|
ReturnValue_t PoolDataSetBase::lockDataPool(MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t lockTimeout) {
|
uint32_t lockTimeout) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::unlockDataPool() {
|
ReturnValue_t PoolDataSetBase::unlockDataPool() {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::serialize(uint8_t** buffer, size_t* size,
|
ReturnValue_t PoolDataSetBase::serialize(uint8_t** buffer, size_t* size,
|
||||||
const size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
const size_t maxSize, SerializeIF::Endianness streamEndianness) const {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
result = registeredVariables[count]->serialize(buffer, size, maxSize,
|
||||||
streamEndianness);
|
streamEndianness);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t PoolDataSetBase::deSerialize(const uint8_t** buffer, size_t* size,
|
ReturnValue_t PoolDataSetBase::deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
SerializeIF::Endianness streamEndianness) {
|
SerializeIF::Endianness streamEndianness) {
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
result = registeredVariables[count]->deSerialize(buffer, size,
|
result = registeredVariables[count]->deSerialize(buffer, size,
|
||||||
streamEndianness);
|
streamEndianness);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PoolDataSetBase::getSerializedSize() const {
|
size_t PoolDataSetBase::getSerializedSize() const {
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
for (uint16_t count = 0; count < fillCount; count++) {
|
for (uint16_t count = 0; count < fillCount; count++) {
|
||||||
size += registeredVariables[count]->getSerializedSize();
|
size += registeredVariables[count]->getSerializedSize();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
|
void PoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
|
||||||
@ -219,13 +222,13 @@ void PoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PoolVariableIF** PoolDataSetBase::getContainer() const {
|
PoolVariableIF** PoolDataSetBase::getContainer() const {
|
||||||
return registeredVariables;
|
return registeredVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolDataSetBase::setReadCommitProtectionBehaviour(
|
void PoolDataSetBase::setReadCommitProtectionBehaviour(
|
||||||
bool protectEveryReadCommit, MutexIF::TimeoutType timeoutType,
|
bool protectEveryReadCommit, MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t mutexTimeout) {
|
uint32_t mutexTimeout) {
|
||||||
this->protectEveryReadCommitCall = protectEveryReadCommit;
|
this->protectEveryReadCommitCall = protectEveryReadCommit;
|
||||||
this->timeoutTypeForSingleVars = timeoutType;
|
this->timeoutTypeForSingleVars = timeoutType;
|
||||||
this->mutexTimeoutForSingleVars = mutexTimeout;
|
this->mutexTimeoutForSingleVars = mutexTimeout;
|
||||||
}
|
}
|
||||||
|
@ -29,98 +29,99 @@
|
|||||||
* @author Bastian Baetz
|
* @author Bastian Baetz
|
||||||
* @ingroup data_pool
|
* @ingroup data_pool
|
||||||
*/
|
*/
|
||||||
class PoolDataSetBase: public PoolDataSetIF,
|
class PoolDataSetBase:
|
||||||
public SerializeIF,
|
public PoolDataSetIF,
|
||||||
public HasReturnvaluesIF {
|
public SerializeIF,
|
||||||
|
public HasReturnvaluesIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates an empty dataset. Use registerVariable or
|
* @brief Creates an empty dataset. Use registerVariable or
|
||||||
* supply a pointer to this dataset to PoolVariable
|
* supply a pointer to this dataset to PoolVariable
|
||||||
* initializations to register pool variables.
|
* initializations to register pool variables.
|
||||||
*/
|
*/
|
||||||
PoolDataSetBase(PoolVariableIF** registeredVariablesArray, const size_t maxFillCount);
|
PoolDataSetBase(PoolVariableIF** registeredVariablesArray, const size_t maxFillCount);
|
||||||
|
|
||||||
/* Forbidden for now */
|
/* Forbidden for now */
|
||||||
PoolDataSetBase(const PoolDataSetBase& otherSet) = delete;
|
PoolDataSetBase(const PoolDataSetBase& otherSet) = delete;
|
||||||
const PoolDataSetBase& operator=(const PoolDataSetBase& otherSet) = delete;
|
const PoolDataSetBase& operator=(const PoolDataSetBase& otherSet) = delete;
|
||||||
|
|
||||||
virtual~ PoolDataSetBase();
|
virtual~ PoolDataSetBase();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The read call initializes reading out all registered variables.
|
* @brief The read call initializes reading out all registered variables.
|
||||||
* It is mandatory to call commit after every read call!
|
* It is mandatory to call commit after every read call!
|
||||||
* @details
|
* @details
|
||||||
* It iterates through the list of registered variables and calls all read()
|
* It iterates through the list of registered variables and calls all read()
|
||||||
* functions of the registered pool variables (which read out their values
|
* functions of the registered pool variables (which read out their values
|
||||||
* from the data pool) which are not write-only.
|
* from the data pool) which are not write-only.
|
||||||
* In case of an error (e.g. a wrong data type, or an invalid data pool id),
|
* In case of an error (e.g. a wrong data type, or an invalid data pool id),
|
||||||
* the operation is aborted and @c INVALID_PARAMETER_DEFINITION returned.
|
* the operation is aborted and @c INVALID_PARAMETER_DEFINITION returned.
|
||||||
*
|
*
|
||||||
* The data pool is locked during the whole read operation and
|
* The data pool is locked during the whole read operation and
|
||||||
* freed afterwards. It is mandatory to call commit after a read call,
|
* freed afterwards. It is mandatory to call commit after a read call,
|
||||||
* even if the read operation is not successful!
|
* even if the read operation is not successful!
|
||||||
* @return
|
* @return
|
||||||
* - @c RETURN_OK if all variables were read successfully.
|
* - @c RETURN_OK if all variables were read successfully.
|
||||||
* - @c INVALID_PARAMETER_DEFINITION if a pool entry does not exist or there
|
* - @c INVALID_PARAMETER_DEFINITION if a pool entry does not exist or there
|
||||||
* is a type conflict.
|
* is a type conflict.
|
||||||
* - @c SET_WAS_ALREADY_READ if read() is called twice without calling
|
* - @c SET_WAS_ALREADY_READ if read() is called twice without calling
|
||||||
* commit() in between
|
* commit() in between
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||||
uint32_t lockTimeout = 20) override;
|
uint32_t lockTimeout = 20) override;
|
||||||
/**
|
/**
|
||||||
* @brief The commit call initializes writing back the registered variables.
|
* @brief The commit call initializes writing back the registered variables.
|
||||||
* @details
|
* @details
|
||||||
* It iterates through the list of registered variables and calls the
|
* It iterates through the list of registered variables and calls the
|
||||||
* commit() method of the remaining registered variables (which write back
|
* commit() method of the remaining registered variables (which write back
|
||||||
* their values to the pool).
|
* their values to the pool).
|
||||||
*
|
*
|
||||||
* The data pool is locked during the whole commit operation and
|
* The data pool is locked during the whole commit operation and
|
||||||
* freed afterwards. The state changes to "was committed" after this operation.
|
* freed afterwards. The state changes to "was committed" after this operation.
|
||||||
*
|
*
|
||||||
* If the set does contain at least one variable which is not write-only
|
* If the set does contain at least one variable which is not write-only
|
||||||
* commit() can only be called after read(). If the set only contains
|
* commit() can only be called after read(). If the set only contains
|
||||||
* variables which are write only, commit() can be called without a
|
* variables which are write only, commit() can be called without a
|
||||||
* preceding read() call. Every read call must be followed by a commit call!
|
* preceding read() call. Every read call must be followed by a commit call!
|
||||||
* @return - @c RETURN_OK if all variables were read successfully.
|
* @return - @c RETURN_OK if all variables were read successfully.
|
||||||
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
* - @c COMMITING_WITHOUT_READING if set was not read yet and
|
||||||
* contains non write-only variables
|
* contains non write-only variables
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
virtual ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||||
uint32_t lockTimeout = 20) override;
|
uint32_t lockTimeout = 20) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the passed pool variable instance into the data set.
|
* Register the passed pool variable instance into the data set.
|
||||||
* @param variable
|
* @param variable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t registerVariable( PoolVariableIF* variable) override;
|
virtual ReturnValue_t registerVariable( PoolVariableIF* variable) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the means to lock the underlying data structure to ensure
|
* Provides the means to lock the underlying data structure to ensure
|
||||||
* thread-safety. Default implementation is empty
|
* thread-safety. Default implementation is empty
|
||||||
* @return Always returns -@c RETURN_OK
|
* @return Always returns -@c RETURN_OK
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t lockDataPool(
|
virtual ReturnValue_t lockDataPool(
|
||||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||||
uint32_t timeoutMs = 20) override;
|
uint32_t timeoutMs = 20) override;
|
||||||
/**
|
/**
|
||||||
* Provides the means to unlock the underlying data structure to ensure
|
* Provides the means to unlock the underlying data structure to ensure
|
||||||
* thread-safety. Default implementation is empty
|
* thread-safety. Default implementation is empty
|
||||||
* @return Always returns -@c RETURN_OK
|
* @return Always returns -@c RETURN_OK
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t unlockDataPool() override;
|
virtual ReturnValue_t unlockDataPool() override;
|
||||||
|
|
||||||
virtual uint16_t getFillCount() const;
|
virtual uint16_t getFillCount() const;
|
||||||
|
|
||||||
/* SerializeIF implementations */
|
/* SerializeIF implementations */
|
||||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
const size_t maxSize,
|
const size_t maxSize,
|
||||||
SerializeIF::Endianness streamEndianness) const override;
|
SerializeIF::Endianness streamEndianness) const override;
|
||||||
virtual size_t getSerializedSize() const override;
|
virtual size_t getSerializedSize() const override;
|
||||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
SerializeIF::Endianness streamEndianness) override;
|
SerializeIF::Endianness streamEndianness) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can be used to individually protect every read and commit call.
|
* Can be used to individually protect every read and commit call.
|
||||||
@ -132,48 +133,48 @@ public:
|
|||||||
uint32_t mutexTimeout = 20);
|
uint32_t mutexTimeout = 20);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The fill_count attribute ensures that the variables
|
* @brief The fill_count attribute ensures that the variables
|
||||||
* register in the correct array position and that the maximum
|
* register in the correct array position and that the maximum
|
||||||
* number of variables is not exceeded.
|
* number of variables is not exceeded.
|
||||||
*/
|
*/
|
||||||
uint16_t fillCount = 0;
|
uint16_t fillCount = 0;
|
||||||
/**
|
/**
|
||||||
* States of the seet.
|
* States of the seet.
|
||||||
*/
|
*/
|
||||||
enum class States {
|
enum class States {
|
||||||
STATE_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
STATE_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED
|
||||||
STATE_SET_WAS_READ //!< DATA_SET_WAS_READ
|
STATE_SET_WAS_READ //!< DATA_SET_WAS_READ
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @brief state manages the internal state of the data set,
|
* @brief state manages the internal state of the data set,
|
||||||
* which is important e.g. for the behavior on destruction.
|
* which is important e.g. for the behavior on destruction.
|
||||||
*/
|
*/
|
||||||
States state = States::STATE_SET_UNINITIALISED;
|
States state = States::STATE_SET_UNINITIALISED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This array represents all pool variables registered in this set.
|
* @brief This array represents all pool variables registered in this set.
|
||||||
* Child classes can use a static or dynamic container to create
|
* Child classes can use a static or dynamic container to create
|
||||||
* an array of registered variables and assign the first entry here.
|
* an array of registered variables and assign the first entry here.
|
||||||
*/
|
*/
|
||||||
PoolVariableIF** registeredVariables = nullptr;
|
PoolVariableIF** registeredVariables = nullptr;
|
||||||
const size_t maxFillCount = 0;
|
const size_t maxFillCount = 0;
|
||||||
|
|
||||||
void setContainer(PoolVariableIF** variablesContainer);
|
void setContainer(PoolVariableIF** variablesContainer);
|
||||||
PoolVariableIF** getContainer() const;
|
PoolVariableIF** getContainer() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool protectEveryReadCommitCall = false;
|
bool protectEveryReadCommitCall = false;
|
||||||
MutexIF::TimeoutType timeoutTypeForSingleVars = MutexIF::TimeoutType::WAITING;
|
MutexIF::TimeoutType timeoutTypeForSingleVars = MutexIF::TimeoutType::WAITING;
|
||||||
uint32_t mutexTimeoutForSingleVars = 20;
|
uint32_t mutexTimeoutForSingleVars = 20;
|
||||||
|
|
||||||
ReturnValue_t readVariable(uint16_t count);
|
ReturnValue_t readVariable(uint16_t count);
|
||||||
void handleAlreadyReadDatasetCommit(
|
void handleAlreadyReadDatasetCommit(
|
||||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||||
uint32_t timeoutMs = 20);
|
uint32_t timeoutMs = 20);
|
||||||
ReturnValue_t handleUnreadDatasetCommit(
|
ReturnValue_t handleUnreadDatasetCommit(
|
||||||
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
|
||||||
uint32_t timeoutMs = 20);
|
uint32_t timeoutMs = 20);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_DATAPOOL_POOLDATASETBASE_H_ */
|
#endif /* FSFW_DATAPOOL_POOLDATASETBASE_H_ */
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
#ifndef FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||||
#define FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
#define FSFW_DATAPOOL_POOLVARIABLEIF_H_
|
||||||
|
|
||||||
|
#include "ReadCommitIF.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../serialize/SerializeIF.h"
|
#include "../serialize/SerializeIF.h"
|
||||||
#include "ReadCommitIF.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This interface is used to control data pool
|
* @brief This interface is used to control data pool
|
||||||
@ -18,46 +19,46 @@
|
|||||||
* @author Bastian Baetz
|
* @author Bastian Baetz
|
||||||
* @ingroup data_pool
|
* @ingroup data_pool
|
||||||
*/
|
*/
|
||||||
class PoolVariableIF : public SerializeIF,
|
class PoolVariableIF :
|
||||||
public ReadCommitIF {
|
public SerializeIF,
|
||||||
friend class PoolDataSetBase;
|
public ReadCommitIF {
|
||||||
friend class LocalPoolDataSetBase;
|
|
||||||
public:
|
public:
|
||||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::POOL_VARIABLE_IF;
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::POOL_VARIABLE_IF;
|
||||||
static constexpr ReturnValue_t INVALID_READ_WRITE_MODE = MAKE_RETURN_CODE(0xA0);
|
static constexpr ReturnValue_t INVALID_READ_WRITE_MODE = MAKE_RETURN_CODE(0xA0);
|
||||||
static constexpr ReturnValue_t INVALID_POOL_ENTRY = MAKE_RETURN_CODE(0xA1);
|
static constexpr ReturnValue_t INVALID_POOL_ENTRY = MAKE_RETURN_CODE(0xA1);
|
||||||
|
|
||||||
static constexpr bool VALID = 1;
|
static constexpr bool VALID = 1;
|
||||||
static constexpr bool INVALID = 0;
|
static constexpr bool INVALID = 0;
|
||||||
static constexpr uint32_t NO_PARAMETER = 0xffffffff;
|
static constexpr uint32_t NO_PARAMETER = 0xffffffff;
|
||||||
|
|
||||||
enum ReadWriteMode_t {
|
enum ReadWriteMode_t {
|
||||||
VAR_READ, VAR_WRITE, VAR_READ_WRITE
|
VAR_READ, VAR_WRITE, VAR_READ_WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is an empty virtual destructor,
|
* @brief This is an empty virtual destructor,
|
||||||
* as it is proposed for C++ interfaces.
|
* as it is proposed for C++ interfaces.
|
||||||
*/
|
*/
|
||||||
virtual ~PoolVariableIF() {}
|
virtual ~PoolVariableIF() {}
|
||||||
/**
|
/**
|
||||||
* @brief This method returns if the variable is write-only,
|
* @brief This method returns if the variable is write-only,
|
||||||
* read-write or read-only.
|
* read-write or read-only.
|
||||||
*/
|
*/
|
||||||
virtual ReadWriteMode_t getReadWriteMode() const = 0;
|
virtual ReadWriteMode_t getReadWriteMode() const = 0;
|
||||||
/**
|
/**
|
||||||
* @brief This operation shall return the data pool id of the variable.
|
* @brief This operation shall return the data pool id of the variable.
|
||||||
*/
|
*/
|
||||||
virtual uint32_t getDataPoolId() const = 0;
|
virtual uint32_t getDataPoolId() const = 0;
|
||||||
/**
|
/**
|
||||||
* @brief With this call, the valid information of the
|
* @brief With this call, the valid information of the
|
||||||
* variable is returned.
|
* variable is returned.
|
||||||
*/
|
*/
|
||||||
virtual bool isValid() const = 0;
|
virtual bool isValid() const = 0;
|
||||||
/**
|
/**
|
||||||
* @brief With this call, the valid information of the variable is set.
|
* @brief With this call, the valid information of the variable is set.
|
||||||
*/
|
*/
|
||||||
virtual void setValid(bool validity) = 0;
|
virtual void setValid(bool validity) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
* semantics.
|
* semantics.
|
||||||
*/
|
*/
|
||||||
class ReadCommitIF {
|
class ReadCommitIF {
|
||||||
|
friend class ReadCommitIFAttorney;
|
||||||
public:
|
public:
|
||||||
virtual ~ReadCommitIF() {}
|
virtual ~ReadCommitIF() {}
|
||||||
virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType,
|
virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType,
|
||||||
@ -16,11 +17,10 @@ public:
|
|||||||
virtual ReturnValue_t commit(MutexIF::TimeoutType timeoutType,
|
virtual ReturnValue_t commit(MutexIF::TimeoutType timeoutType,
|
||||||
uint32_t timeoutMs) = 0;
|
uint32_t timeoutMs) = 0;
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
|
|
||||||
//! Optional and protected because this is interesting for classes grouping
|
/* Optional and protected because this is interesting for classes grouping members with commit
|
||||||
//! members with commit and read semantics where the lock is only necessary
|
and read semantics where the lock is only necessary once. */
|
||||||
//! once.
|
|
||||||
virtual ReturnValue_t readWithoutLock() {
|
virtual ReturnValue_t readWithoutLock() {
|
||||||
return read(MutexIF::TimeoutType::WAITING, 20);
|
return read(MutexIF::TimeoutType::WAITING, 20);
|
||||||
}
|
}
|
||||||
|
32
datapool/ReadCommitIFAttorney.h
Normal file
32
datapool/ReadCommitIFAttorney.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef FSFW_DATAPOOL_READCOMMITIFATTORNEY_H_
|
||||||
|
#define FSFW_DATAPOOL_READCOMMITIFATTORNEY_H_
|
||||||
|
|
||||||
|
#include <fsfw/datapool/ReadCommitIF.h>
|
||||||
|
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This class determines which members are allowed to access protected members
|
||||||
|
* of the ReadCommitIF.
|
||||||
|
*/
|
||||||
|
class ReadCommitIFAttorney {
|
||||||
|
private:
|
||||||
|
static ReturnValue_t readWithoutLock(ReadCommitIF* readCommitIF) {
|
||||||
|
if(readCommitIF == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return readCommitIF->readWithoutLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
static ReturnValue_t commitWithoutLock(ReadCommitIF* readCommitIF) {
|
||||||
|
if(readCommitIF == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return readCommitIF->commitWithoutLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
friend class PoolDataSetBase;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_DATAPOOL_READCOMMITIFATTORNEY_H_ */
|
Loading…
Reference in New Issue
Block a user