#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ #error Include LocalPoolVariable.h before LocalPoolVariable.tpp! #endif template inline LocalPoolVariable::LocalPoolVariable(HasLocalDataPoolIF* hkOwner, lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} template inline LocalPoolVariable::LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} template inline LocalPoolVariable::LocalPoolVariable(gp_id_t globalPoolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, dataSet, setReadWriteMode){} template inline ReturnValue_t LocalPoolVariable::read( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { if(hkManager == nullptr) { return readWithoutLock(); } MutexIF* mutex = LocalDpManagerAttorney::getMutexHandle(*hkManager); ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); if(result != HasReturnvaluesIF::RETURN_OK) { return result; } result = readWithoutLock(); mutex->unlockMutex(); return result; } template inline ReturnValue_t LocalPoolVariable::readWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_WRITE) { object_id_t targetObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVector", PoolVariableIF::INVALID_READ_WRITE_MODE, true, targetObjectId, localPoolId); return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, &poolEntry); if(result != RETURN_OK) { object_id_t ownerObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVariable", result, false, ownerObjectId, localPoolId); return result; } this->value = *(poolEntry->getDataPtr()); this->valid = poolEntry->getValid(); return RETURN_OK; } template inline ReturnValue_t LocalPoolVariable::commit(bool setValid, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { this->setValid(setValid); return commit(timeoutType, timeoutMs); } template inline ReturnValue_t LocalPoolVariable::commit( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { if(hkManager == nullptr) { return commitWithoutLock(); } MutexIF* mutex = LocalDpManagerAttorney::getMutexHandle(*hkManager); ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); if(result != HasReturnvaluesIF::RETURN_OK) { return result; } result = commitWithoutLock(); mutex->unlockMutex(); return result; } template inline ReturnValue_t LocalPoolVariable::commitWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_READ) { object_id_t targetObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVector", PoolVariableIF::INVALID_READ_WRITE_MODE, false, targetObjectId, localPoolId); return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, &poolEntry); if(result != RETURN_OK) { object_id_t ownerObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVariable", result, false, ownerObjectId, localPoolId); return result; } *(poolEntry->getDataPtr()) = this->value; poolEntry->setValid(this->valid); return RETURN_OK; } template inline ReturnValue_t LocalPoolVariable::serialize(uint8_t** buffer, size_t* size, const size_t max_size, SerializeIF::Endianness streamEndianness) const { return SerializeAdapter::serialize(&value, buffer, size ,max_size, streamEndianness); } template inline size_t LocalPoolVariable::getSerializedSize() const { return SerializeAdapter::getSerializedSize(&value); } template inline ReturnValue_t LocalPoolVariable::deSerialize(const uint8_t** buffer, size_t* size, SerializeIF::Endianness streamEndianness) { return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); } #if FSFW_CPP_OSTREAM_ENABLED == 1 template inline std::ostream& operator<< (std::ostream &out, const LocalPoolVariable &var) { out << var.value; return out; } #endif template inline LocalPoolVariable::operator T() const { return value; } template inline LocalPoolVariable & LocalPoolVariable::operator=( const T& newValue) { value = newValue; return *this; } template inline LocalPoolVariable& LocalPoolVariable::operator =( const LocalPoolVariable& newPoolVariable) { value = newPoolVariable.value; return *this; } template inline bool LocalPoolVariable::operator ==( const LocalPoolVariable &other) const { return this->value == other.value; } template inline bool LocalPoolVariable::operator ==(const T &other) const { return this->value == other; } template inline bool LocalPoolVariable::operator !=( const LocalPoolVariable &other) const { return not (*this == other); } template inline bool LocalPoolVariable::operator !=(const T &other) const { return not (*this == other); } template inline bool LocalPoolVariable::operator <( const LocalPoolVariable &other) const { return this->value < other.value; } template inline bool LocalPoolVariable::operator <(const T &other) const { return this->value < other; } template inline bool LocalPoolVariable::operator >( const LocalPoolVariable &other) const { return not (*this < other); } template inline bool LocalPoolVariable::operator >(const T &other) const { return not (*this < other); } #endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */