#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(dur_millis_t lockTimeout) { MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING, lockTimeout); return readWithoutLock(); } template inline ReturnValue_t LocalPoolVariable::readWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_WRITE) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LocalPoolVariable: Invalid read write " "mode for read call." << std::endl; #else fsfw::printWarning("LocalPoolVariable: Invalid read write " "mode for read call."); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK or poolEntry == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PoolPoolVariable: Read of local pool variable of object " << std::hex << std::setw(8) << std::setfill('0') << hkManager->getOwner() << " and lp ID 0x" << localPoolId << std::dec << " failed." << std::setfill(' ') << std::endl; #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 */ return result; } this->value = *(poolEntry->address); this->valid = poolEntry->valid; return RETURN_OK; } template inline ReturnValue_t LocalPoolVariable::commit(dur_millis_t lockTimeout) { MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING, lockTimeout); return commitWithoutLock(); } template inline ReturnValue_t LocalPoolVariable::commitWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_READ) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LocalPoolVariable: Invalid read write " "mode for commit() call." << std::endl; #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PoolPoolVariable: Read of local pool variable of " << "object " << std::hex << std::setw(8) << std::setfill('0') << hkManager->getOwner() << " and lp ID 0x" << localPoolId << std::dec << " failed." << std::endl; #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 */ return result; } *(poolEntry->address) = this->value; poolEntry->valid = 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_ */