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>
|
2021-01-06 21:14:23 +01:00
|
|
|
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 "
|
2021-01-06 19:49:58 +01:00
|
|
|
"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);
|
2020-12-26 18:06:56 +01:00
|
|
|
if(result != RETURN_OK or poolEntry == nullptr) {
|
2021-01-07 19:10:07 +01:00
|
|
|
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
|
|
|
|
reportReadCommitError(true, ownerObjectId, localPoolId);
|
2020-10-01 12:05:24 +02:00
|
|
|
return result;
|
|
|
|
}
|
2021-01-07 19:10:07 +01:00
|
|
|
|
|
|
|
if(poolEntry->address == nullptr) {
|
|
|
|
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
|
|
|
|
reportReadCommitError(true, ownerObjectId, localPoolId);
|
|
|
|
return PoolVariableIF::INVALID_POOL_ENTRY;
|
|
|
|
}
|
|
|
|
|
2020-10-01 12:05:24 +02:00
|
|
|
this->value = *(poolEntry->address);
|
|
|
|
this->valid = poolEntry->valid;
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2021-01-06 21:14:23 +01:00
|
|
|
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 "
|
2021-01-06 19:49:58 +01:00
|
|
|
"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 19:10:07 +01:00
|
|
|
if(result != RETURN_OK or poolEntry == nullptr) {
|
|
|
|
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
|
|
|
|
reportReadCommitError(false, ownerObjectId, localPoolId);
|
2020-10-01 12:05:24 +02:00
|
|
|
return result;
|
|
|
|
}
|
2021-01-07 19:10:07 +01:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-07 19:10:07 +01:00
|
|
|
template<typename T>
|
|
|
|
inline void LocalPoolVariable<T>::reportReadCommitError(bool read,
|
|
|
|
object_id_t objectId, lp_id_t lpId) {
|
|
|
|
const char* type = nullptr;
|
|
|
|
if(read) {
|
|
|
|
type = "read";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
type = "commit";
|
|
|
|
}
|
|
|
|
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "PoolPoolVariable: " << type << " of local pool "
|
|
|
|
<<"variable of object " << std::hex << std::setw(8)
|
|
|
|
<< std::setfill('0') << objectId << " and lp ID 0x" << lpId
|
|
|
|
<< std::dec << " failed." << std::endl;
|
|
|
|
#else
|
|
|
|
fsfw::printWarning("LocalPoolVariable: %s of local pool variable of "
|
|
|
|
"object 0x%08x and lp ID 0x%08x failed.\n\r",
|
|
|
|
type, objectId, lpId);
|
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 13:00:04 +01:00
|
|
|
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */
|