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,
HasHkPoolParametersIF* hkOwner, pool_rwm_t setReadWriteMode,
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-05-17 01:17:11 +02:00
HasHkPoolParametersIF* hkOwner =
objectManager->get<HasHkPoolParametersIF>(poolOwner);
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-05 20:34:34 +02:00
inline ReturnValue_t LocalPoolVar<T>::read(millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
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-05 20:34:34 +02:00
inline ReturnValue_t LocalPoolVar<T>::commit(millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
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
}
2020-06-05 20:34:34 +02:00
// Wait maximum of 50 milliseconds.
MutexHelper(hkManager->getMutexHandle(), 50);
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,
const size_t max_size, bool bigEndian) const {
return AutoSerializeAdapter::serialize(&value,
buffer, size ,max_size, bigEndian);
}
template<typename T>
inline size_t LocalPoolVar<T>::getSerializedSize() const {
return AutoSerializeAdapter::getSerializedSize(&value);
}
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::deSerialize(const uint8_t** buffer,
size_t* size, bool bigEndian) {
return AutoSerializeAdapter::deSerialize(&value, buffer, size, bigEndian);
}
2020-05-18 15:42:47 +02:00
2020-06-05 20:34:34 +02:00
//template<typename T>
//inline friend std::ostream& LocalPoolVar<T>::operator<< (std::ostream &out,
// const LocalPoolVar &var) {
// out << static_cast<int>(out);
//}
2020-05-18 15:42:47 +02:00
#endif