fsfw/datapoollocal/LocalPoolVariable.tpp

197 lines
6.0 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>
2020-12-27 00:21:39 +01:00
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>
2020-12-27 00:21:39 +01:00
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) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-06 16:26:08 +01:00
sif::warning << "LocalPoolVariable: Invalid read write "
2021-01-06 19:32:33 +01:00
"mode for read call." << std::endl;
#else
fsfw::printWarning("LocalPoolVariable: Invalid read write "
"mode for read call.");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
2020-10-01 12:05:24 +02:00
return PoolVariableIF::INVALID_READ_WRITE_MODE;
}
PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
2020-12-26 18:06:56 +01:00
if(result != RETURN_OK or poolEntry == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-06 16:26:08 +01:00
sif::error << "PoolPoolVariable: Read of local pool variable of object "
2020-12-26 18:06:56 +01:00
<< std::hex << std::setw(8) << std::setfill('0')
2021-01-06 18:20:38 +01:00
<< hkManager->getOwner() << " and lp ID 0x" << localPoolId
2020-12-26 18:06:56 +01:00
<< std::dec << " failed." << std::setfill(' ') << std::endl;
2021-01-06 19:32:33 +01:00
#else
fsfw::printError("LocalPoolVariable: Read of local pool variable of "
"object 0x%08x and lp ID 0x08x failed.", hkManager->getOwner(),
localPoolId);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
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) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-06 16:26:08 +01:00
sif::warning << "LocalPoolVariable: Invalid read write "
2020-10-01 12:05:24 +02:00
"mode for commit() call." << std::endl;
2021-01-06 19:32:33 +01:00
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
2020-10-01 12:05:24 +02:00
return PoolVariableIF::INVALID_READ_WRITE_MODE;
}
PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-06 16:26:08 +01:00
sif::error << "PoolPoolVariable: Read of local pool variable of "
<< "object " << std::hex << std::setw(8) << std::setfill('0')
2021-01-06 18:20:38 +01:00
<< hkManager->getOwner() << " and lp ID 0x" << localPoolId
2021-01-06 16:26:08 +01:00
<< std::dec << " failed." << std::endl;
2021-01-06 19:32:33 +01:00
#else
fsfw::printError("LocalPoolVariable: Read of local pool variable of "
"object 0x%08x and lp ID 0x08x failed.", hkManager->getOwner(),
localPoolId);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
2020-10-01 12:05:24 +02:00
return result;
}
*(poolEntry->address) = this->value;
poolEntry->valid = this->valid;
return RETURN_OK;
}
template<typename T>
2021-01-06 16:26:08 +01:00
inline ReturnValue_t LocalPoolVariable<T>::serialize(uint8_t** buffer,
size_t* size, const size_t max_size,
SerializeIF::Endianness streamEndianness) const {
2020-12-03 13:00:04 +01:00
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
}
2021-01-03 14:41:54 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
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;
}
2021-01-03 14:41:54 +01:00
#endif
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>
2021-01-06 16:26:08 +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>
2021-01-06 16:26:08 +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>
2021-01-06 16:26:08 +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>
2021-01-06 16:26:08 +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>
2021-01-06 16:26:08 +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_ */