fsfw/datapoollocal/LocalPoolVariable.tpp

162 lines
4.8 KiB
C++
Raw Normal View History

2020-05-18 15:42:47 +02:00
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
#define FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
2020-05-17 01:17:11 +02:00
2020-06-05 20:34:34 +02:00
#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
#error Include LocalPoolVariable.h before LocalPoolVariable.tpp!
#endif
2020-05-17 01:17:11 +02:00
template<typename T>
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId,
2020-07-09 00:59:10 +02:00
HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode,
2020-05-17 01:17:11 +02:00
DataSetIF* dataSet):
localPoolId(poolId),readWriteMode(setReadWriteMode) {
2020-06-05 20:34:34 +02:00
if(poolId == PoolVariableIF::NO_PARAMETER) {
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
"NO_PARAMETER value!" << std::endl;
}
if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner is a nullptr!"
<< std::endl;
return;
}
2020-05-17 01:17:11 +02:00
hkManager = hkOwner->getHkManagerHandle();
if(dataSet != nullptr) {
dataSet->registerVariable(this);
}
}
template<typename T>
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
pool_rwm_t setReadWriteMode, DataSetIF *dataSet):
readWriteMode(readWriteMode) {
2020-06-05 20:34:34 +02:00
if(poolId == PoolVariableIF::NO_PARAMETER) {
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
"NO_PARAMETER value!" << std::endl;
}
2020-07-09 00:59:10 +02:00
HasLocalDataPoolIF* hkOwner =
objectManager->get<HasLocalDataPoolIF>(poolOwner);
2020-05-17 01:17:11 +02:00
if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
"the correct interface HasHkPoolParametersIF!" << std::endl;
return;
}
hkManager = hkOwner->getHkManagerHandle();
if(dataSet != nullptr) {
dataSet->registerVariable(this);
}
}
template<typename T>
2020-06-07 02:22:18 +02:00
inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) {
2020-08-07 22:15:03 +02:00
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
2020-06-05 20:34:34 +02:00
return readWithoutLock();
}
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::readWithoutLock() {
2020-05-17 01:17:11 +02:00
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
sif::debug << "LocalPoolVar: Invalid read write "
"mode for read() call." << std::endl;
2020-06-05 20:34:34 +02:00
return PoolVariableIF::INVALID_READ_WRITE_MODE;
2020-05-17 01:17:11 +02:00
}
2020-06-05 20:34:34 +02:00
2020-05-17 01:17:11 +02:00
PoolEntry<T>* poolEntry = nullptr;
2020-06-05 20:34:34 +02:00
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK and poolEntry != nullptr) {
sif::error << "PoolVector: Read of local pool variable of object "
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
std::dec << " failed.\n" << std::flush;
2020-05-17 01:17:11 +02:00
return result;
}
this->value = *(poolEntry->address);
2020-06-05 20:34:34 +02:00
this->valid = poolEntry->valid;
2020-05-17 01:17:11 +02:00
return RETURN_OK;
}
template<typename T>
2020-06-07 02:22:18 +02:00
inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) {
2020-08-07 22:15:03 +02:00
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
2020-06-05 20:34:34 +02:00
return commitWithoutLock();
}
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::commitWithoutLock() {
2020-05-17 01:17:11 +02:00
if(readWriteMode == pool_rwm_t::VAR_READ) {
sif::debug << "LocalPoolVar: Invalid read write "
"mode for commit() call." << std::endl;
2020-06-05 20:34:34 +02:00
return PoolVariableIF::INVALID_READ_WRITE_MODE;
2020-05-17 01:17:11 +02:00
}
PoolEntry<T>* poolEntry = nullptr;
2020-06-05 20:34:34 +02:00
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
2020-05-17 01:17:11 +02:00
if(result != RETURN_OK) {
2020-06-05 20:34:34 +02:00
sif::error << "PoolVector: Read of local pool variable of object "
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
std::dec << " failed.\n" << std::flush;
2020-05-17 01:17:11 +02:00
return result;
}
*(poolEntry->address) = this->value;
2020-06-05 20:34:34 +02:00
poolEntry->valid = this->valid;
2020-05-17 01:17:11 +02:00
return RETURN_OK;
}
template<typename T>
inline pool_rwm_t LocalPoolVar<T>::getReadWriteMode() const {
return readWriteMode;
}
template<typename T>
inline lp_id_t LocalPoolVar<T>::getDataPoolId() const {
return localPoolId;
}
2020-06-05 20:34:34 +02:00
template<typename T>
inline void LocalPoolVar<T>::setDataPoolId(lp_id_t poolId) {
this->localPoolId = poolId;
}
2020-05-17 01:17:11 +02:00
template<typename T>
inline bool LocalPoolVar<T>::isValid() const {
return valid;
}
template<typename T>
2020-06-05 20:34:34 +02:00
inline void LocalPoolVar<T>::setValid(bool validity) {
2020-05-17 01:17:11 +02:00
this->valid = validity;
}
2020-06-05 20:34:34 +02:00
template<typename T>
inline uint8_t LocalPoolVar<T>::getValid() const {
return valid;
}
2020-05-17 01:17:11 +02:00
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size,
2020-07-01 14:17:55 +02:00
const size_t max_size, SerializeIF::Endianness streamEndianness) const {
return SerializeAdapter::serialize(&value,
buffer, size ,max_size, streamEndianness);
2020-05-17 01:17:11 +02:00
}
template<typename T>
inline size_t LocalPoolVar<T>::getSerializedSize() const {
2020-07-01 14:17:55 +02:00
return SerializeAdapter::getSerializedSize(&value);
2020-05-17 01:17:11 +02:00
}
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::deSerialize(const uint8_t** buffer,
2020-07-01 14:17:55 +02:00
size_t* size, SerializeIF::Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
2020-05-17 01:17:11 +02:00
}
2020-05-18 15:42:47 +02:00
2020-06-06 23:15:05 +02:00
template<typename T>
inline std::ostream& operator<< (std::ostream &out,
const LocalPoolVar<T> &var) {
out << var.value;
return out;
}
2020-06-05 20:34:34 +02:00
2020-05-18 15:42:47 +02:00
#endif