fsfw/datapoollocal/LocalPoolVariable.tpp

170 lines
5.0 KiB
C++
Raw Normal View History

2020-09-28 21:28:03 +02:00
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
2020-05-17 01:17:11 +02:00
2020-09-28 21:28:03 +02:00
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
2020-06-05 20:34:34 +02:00
#error Include LocalPoolVariable.h before LocalPoolVariable.tpp!
#endif
2020-05-17 01:17:11 +02:00
template<typename T>
2020-11-30 14:13:52 +01:00
inline LocalPoolVar<T>::LocalPoolVar(HasLocalDataPoolIF* hkOwner,
lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
2020-10-14 01:25:15 +02:00
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
2020-05-17 01:17:11 +02:00
template<typename T>
2020-11-30 13:59:54 +01:00
inline LocalPoolVar<T>::LocalPoolVar(object_id_t poolOwner, lp_id_t poolId,
2020-09-28 21:09:56 +02:00
DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
2020-11-30 13:59:54 +01:00
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
template<typename T>
inline LocalPoolVar<T>::LocalPoolVar(gp_id_t globalPoolId, DataSetIF *dataSet,
pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
dataSet, setReadWriteMode){}
2020-05-17 01:17:11 +02:00
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 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
template<typename T>
inline LocalPoolVar<T>::operator T() const {
return value;
}
template<typename T>
inline LocalPoolVar<T> & LocalPoolVar<T>::operator=(const T& newValue) {
value = newValue;
return *this;
}
template<typename T>
inline LocalPoolVar<T>& LocalPoolVar<T>::operator =(
const LocalPoolVar<T>& newPoolVariable) {
value = newPoolVariable.value;
return *this;
}
2020-11-30 16:06:59 +01:00
template<typename T>
inline bool LocalPoolVar<T>::operator ==(const LocalPoolVar<T> &other) const {
return this->value == other.value;
}
template<typename T>
inline bool LocalPoolVar<T>::operator ==(const T &other) const {
return this->value == other;
}
template<typename T>
inline bool LocalPoolVar<T>::operator !=(const LocalPoolVar<T> &other) const {
return not (*this == other);
}
template<typename T>
inline bool LocalPoolVar<T>::operator !=(const T &other) const {
return not (*this == other);
}
template<typename T>
inline bool LocalPoolVar<T>::operator <(const LocalPoolVar<T> &other) const {
return this->value < other.value;
}
template<typename T>
inline bool LocalPoolVar<T>::operator <(const T &other) const {
return this->value < other;
}
template<typename T>
inline bool LocalPoolVar<T>::operator >(const LocalPoolVar<T> &other) const {
return not (*this < other);
}
template<typename T>
inline bool LocalPoolVar<T>::operator >(const T &other) const {
return not (*this < other);
}
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */