fsfw/datapoollocal/PoolReadHelper.h

50 lines
1.2 KiB
C
Raw Normal View History

2020-12-27 01:52:48 +01:00
#ifndef FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_
#define FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_
2021-01-12 20:46:34 +01:00
#include "LocalPoolDataSetBase.h"
#include "../serviceinterface/ServiceInterface.h"
2020-12-27 01:52:48 +01:00
#include <FSFWConfig.h>
/**
* @brief Helper class to read data sets or pool variables
*/
class PoolReadHelper {
public:
2021-01-06 21:33:54 +01:00
PoolReadHelper(ReadCommitIF* readObject,
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
uint32_t mutexTimeout = 20):
2020-12-27 01:52:48 +01:00
readObject(readObject), mutexTimeout(mutexTimeout) {
if(readObject != nullptr) {
2021-01-06 21:33:54 +01:00
readResult = readObject->read(timeoutType, mutexTimeout);
2020-12-27 01:52:48 +01:00
#if FSFW_PRINT_VERBOSITY_LEVEL == 1
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2020-12-27 01:52:48 +01:00
sif::error << "PoolReadHelper: Read failed!" << std::endl;
#endif
2021-01-12 20:46:34 +01:00
#else
sif::printError("PoolReadHelper: Read failed!\n");
2020-12-27 01:52:48 +01:00
#endif
}
}
ReturnValue_t getReadResult() const {
return readResult;
}
~PoolReadHelper() {
if(readObject != nullptr) {
2021-01-06 21:33:54 +01:00
readObject->commit(timeoutType, mutexTimeout);
2020-12-27 01:52:48 +01:00
}
}
private:
ReadCommitIF* readObject = nullptr;
ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK;
2021-01-06 21:33:54 +01:00
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
2020-12-27 01:52:48 +01:00
uint32_t mutexTimeout = 20;
};
#endif /* FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_ */