Files
fsfw/datapoollocal/PoolReadHelper.h
T

50 lines
1.4 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-13 11:53: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-13 12:41:24 +01:00
PoolReadHelper(ReadCommitIF* readObject,
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
uint32_t mutexTimeout = 20):
readObject(readObject), mutexTimeout(mutexTimeout) {
if(readObject != nullptr) {
readResult = readObject->read(timeoutType, mutexTimeout);
2021-01-13 11:53:34 +01:00
#if FSFW_VERBOSE_LEVEL == 1
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-13 12:41:24 +01:00
sif::error << "PoolReadHelper: Read failed!" << std::endl;
2021-01-13 11:53:34 +01:00
#else
2021-01-13 12:41:24 +01:00
sif::printError("PoolReadHelper: Read failed!\n");
#endif /* FSFW_PRINT_VERBOSITY_LEVEL == 1 */
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
2021-01-13 12:41:24 +01:00
}
}
2020-12-27 01:52:48 +01:00
2021-01-13 12:41:24 +01:00
ReturnValue_t getReadResult() const {
return readResult;
}
2020-12-27 01:52:48 +01:00
2021-01-13 12:41:24 +01:00
~PoolReadHelper() {
if(readObject != nullptr) {
readObject->commit(timeoutType, mutexTimeout);
}
2020-12-27 01:52:48 +01:00
2021-01-13 12:41:24 +01:00
}
2020-12-27 01:52:48 +01:00
private:
2021-01-13 12:41:24 +01:00
ReadCommitIF* readObject = nullptr;
ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
uint32_t mutexTimeout = 20;
2020-12-27 01:52:48 +01:00
};
#endif /* FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_ */