fsfw/datapoollocal/LocalPoolVariable.tpp

204 lines
5.9 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>
inline ReturnValue_t LocalPoolVariable<T>::read(
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs);
2020-10-01 12:05:24 +02:00
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.\n\r");
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);
2021-01-07 20:23:23 +01:00
if(result != RETURN_OK) {
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
2021-01-07 20:23:23 +01:00
reportReadCommitError("LocalPoolVariable", result,
false, ownerObjectId, localPoolId);
2020-10-01 12:05:24 +02:00
return result;
}
2021-01-07 20:23:23 +01:00
// Actually this should never happen..
if(poolEntry->address == nullptr) {
2021-01-07 20:23:23 +01:00
result = PoolVariableIF::INVALID_POOL_ENTRY;
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
2021-01-07 20:23:23 +01:00
reportReadCommitError("LocalPoolVariable", result,
false, ownerObjectId, localPoolId);
return result;
}
2020-10-01 12:05:24 +02:00
this->value = *(poolEntry->address);
this->valid = poolEntry->valid;
return RETURN_OK;
}
template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::commit(bool setValid,
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
this->setValid(setValid);
return commit(timeoutType, timeoutMs);
}
template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::commit(
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs);
2020-10-01 12:05:24 +02:00
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 "
"mode for commit call." << std::endl;
#else
fsfw::printWarning("LocalPoolVariable: Invalid read write "
"mode for commit call.\n\r");
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);
2021-01-07 20:23:23 +01:00
if(result != RETURN_OK) {
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
2021-01-07 20:23:23 +01:00
reportReadCommitError("LocalPoolVariable", result,
false, ownerObjectId, localPoolId);
2020-10-01 12:05:24 +02:00
return result;
}
2020-10-01 12:05:24 +02:00
*(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_ */