fsfw/datapoollocal/LocalPoolVariable.tpp

170 lines
5.2 KiB
C++
Raw Normal View History

2020-10-01 12:05:24 +02:00
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_
#error Include LocalPoolVariable.h before LocalPoolVariable.tpp!
#endif
template<typename T>
2020-12-14 22:56:30 +01:00
inline LocalPoolVariable<T>::LocalPoolVariable(HasLocalDataPoolIF* hkOwner,
2020-12-03 13:00:04 +01:00
lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
2020-10-01 12:05:24 +02:00
template<typename T>
inline LocalPoolVariable<T>::LocalPoolVariable(object_id_t poolOwner,
lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
2020-12-03 13:00:04 +01:00
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
template<typename T>
inline LocalPoolVariable<T>::LocalPoolVariable(gp_id_t globalPoolId,
DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
2020-12-03 13:00:04 +01:00
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
dataSet, setReadWriteMode){}
2020-10-01 12:05:24 +02:00
template<typename T>
2020-12-14 22:56:30 +01:00
inline ReturnValue_t LocalPoolVariable<T>::read(dur_millis_t lockTimeout) {
2020-10-01 12:05:24 +02:00
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return readWithoutLock();
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline ReturnValue_t LocalPoolVariable<T>::readWithoutLock() {
2020-10-01 12:05:24 +02:00
if(readWriteMode == pool_rwm_t::VAR_WRITE) {
sif::debug << "LocalPoolVar: Invalid read write "
"mode for read() call." << std::endl;
return PoolVariableIF::INVALID_READ_WRITE_MODE;
}
PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK or poolEntry == nullptr) {
2020-10-01 12:05:24 +02:00
sif::error << "PoolVector: Read of local pool variable of object "
<< std::hex << std::setw(8) << std::setfill('0')
<< hkManager->getOwner() << " and lp ID " << localPoolId
<< std::dec << " failed." << std::setfill(' ') << std::endl;
2020-10-01 12:05:24 +02:00
return result;
}
this->value = *(poolEntry->address);
this->valid = poolEntry->valid;
return RETURN_OK;
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline ReturnValue_t LocalPoolVariable<T>::commit(dur_millis_t lockTimeout) {
2020-10-01 12:05:24 +02:00
MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING,
lockTimeout);
return commitWithoutLock();
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline ReturnValue_t LocalPoolVariable<T>::commitWithoutLock() {
2020-10-01 12:05:24 +02:00
if(readWriteMode == pool_rwm_t::VAR_READ) {
sif::debug << "LocalPoolVariable: Invalid read write "
2020-10-01 12:05:24 +02:00
"mode for commit() call." << std::endl;
return PoolVariableIF::INVALID_READ_WRITE_MODE;
}
PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK) {
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;
return result;
}
*(poolEntry->address) = this->value;
poolEntry->valid = this->valid;
return RETURN_OK;
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline ReturnValue_t LocalPoolVariable<T>::serialize(uint8_t** buffer, size_t* size,
2020-12-03 13:00:04 +01:00
const size_t max_size, SerializeIF::Endianness streamEndianness) const {
return SerializeAdapter::serialize(&value,
buffer, size ,max_size, streamEndianness);
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline size_t LocalPoolVariable<T>::getSerializedSize() const {
2020-12-03 13:00:04 +01:00
return SerializeAdapter::getSerializedSize(&value);
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline ReturnValue_t LocalPoolVariable<T>::deSerialize(const uint8_t** buffer,
2020-12-03 13:00:04 +01:00
size_t* size, SerializeIF::Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
2020-10-01 12:05:24 +02:00
}
2020-12-03 13:00:04 +01:00
template<typename T>
inline std::ostream& operator<< (std::ostream &out,
2020-12-14 22:56:30 +01:00
const LocalPoolVariable<T> &var) {
2020-12-03 13:00:04 +01:00
out << var.value;
return out;
}
2020-10-01 12:05:24 +02:00
template<typename T>
2020-12-14 22:56:30 +01:00
inline LocalPoolVariable<T>::operator T() const {
2020-12-03 13:00:04 +01:00
return value;
2020-10-01 12:05:24 +02:00
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline LocalPoolVariable<T> & LocalPoolVariable<T>::operator=(const T& newValue) {
2020-12-03 13:00:04 +01:00
value = newValue;
return *this;
2020-10-01 12:05:24 +02:00
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline LocalPoolVariable<T>& LocalPoolVariable<T>::operator =(
const LocalPoolVariable<T>& newPoolVariable) {
2020-12-03 13:00:04 +01:00
value = newPoolVariable.value;
return *this;
2020-10-01 12:05:24 +02:00
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator ==(const LocalPoolVariable<T> &other) const {
2020-12-03 13:00:04 +01:00
return this->value == other.value;
2020-10-01 12:05:24 +02:00
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator ==(const T &other) const {
2020-12-03 13:00:04 +01:00
return this->value == other;
2020-10-01 12:05:24 +02:00
}
2020-12-03 13:00:04 +01:00
2020-10-01 12:05:24 +02:00
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator !=(const LocalPoolVariable<T> &other) const {
2020-12-03 13:00:04 +01:00
return not (*this == other);
2020-10-01 12:05:24 +02:00
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator !=(const T &other) const {
2020-12-03 13:00:04 +01:00
return not (*this == other);
2020-10-01 12:05:24 +02:00
}
2020-12-03 13:00:04 +01:00
2020-10-01 12:05:24 +02:00
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator <(const LocalPoolVariable<T> &other) const {
2020-12-03 13:00:04 +01:00
return this->value < other.value;
2020-10-01 12:05:24 +02:00
}
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator <(const T &other) const {
2020-12-03 13:00:04 +01:00
return this->value < other;
2020-10-01 12:05:24 +02:00
}
2020-12-03 13:00:04 +01:00
2020-10-01 12:05:24 +02:00
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator >(const LocalPoolVariable<T> &other) const {
2020-12-03 13:00:04 +01:00
return not (*this < other);
2020-10-01 12:05:24 +02:00
}
2020-12-03 13:00:04 +01:00
template<typename T>
2020-12-14 22:56:30 +01:00
inline bool LocalPoolVariable<T>::operator >(const T &other) const {
2020-12-03 13:00:04 +01:00
return not (*this < other);
}
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */