#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 LocalPoolVar::LocalPoolVar(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): localPoolId(poolId), readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { sif::warning << "LocalPoolVar::LocalPoolVar: 0 passed as pool ID, " << "which is the NO_PARAMETER value!" << std::endl; } if(hkOwner == nullptr) { sif::error << "LocalPoolVar::LocalPoolVar: The supplied pool " << "owner is a invalid!" << std::endl; return; } hkManager = hkOwner->getHkManagerHandle(); if(dataSet != nullptr) { dataSet->registerVariable(this); } } template inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): localPoolId(poolId), readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { sif::warning << "LocalPoolVar::LocalPoolVar: 0 passed as pool ID, " << "which is the NO_PARAMETER value!" << std::endl; } HasLocalDataPoolIF* hkOwner = objectManager->get(poolOwner); if(hkOwner == nullptr) { sif::error << "LocalPoolVariable: The supplied pool owner did not " << "implement the correct interface " << "HasLocalDataPoolIF!" << std::endl; return; } hkManager = hkOwner->getHkManagerHandle(); if(dataSet != nullptr) { dataSet->registerVariable(this); } } template inline ReturnValue_t LocalPoolVar::read(dur_millis_t lockTimeout) { MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING, lockTimeout); return readWithoutLock(); } template inline ReturnValue_t LocalPoolVar::readWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_WRITE) { sif::debug << "LocalPoolVar: Invalid read write " "mode for read() call." << std::endl; return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK and poolEntry != nullptr) { sif::error << "PoolVector: Read of local pool variable of object " "0x" << std::hex << std::setw(8) << std::setfill('0') << hkManager->getOwner() << " and lp ID 0x" << localPoolId << std::dec << " failed.\n" << std::flush; return result; } this->value = *(poolEntry->address); this->valid = poolEntry->valid; return RETURN_OK; } template inline ReturnValue_t LocalPoolVar::commit(dur_millis_t lockTimeout) { MutexHelper(hkManager->getMutexHandle(), MutexIF::TimeoutType::WAITING, lockTimeout); return commitWithoutLock(); } template inline ReturnValue_t LocalPoolVar::commitWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_READ) { sif::debug << "LocalPoolVar: Invalid read write " "mode for commit() call." << std::endl; return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK) { sif::error << "PoolVector: Read of local pool variable of object " "0x" << std::hex << std::setw(8) << std::setfill('0') << hkManager->getOwner() << " and lp ID 0x" << localPoolId << std::dec << " failed.\n" << std::flush; return result; } *(poolEntry->address) = this->value; poolEntry->valid = this->valid; return RETURN_OK; } template inline LocalPoolVar & LocalPoolVar::operator =(T newValue) { value = newValue; return *this; } template inline pool_rwm_t LocalPoolVar::getReadWriteMode() const { return readWriteMode; } template inline lp_id_t LocalPoolVar::getDataPoolId() const { return localPoolId; } template inline void LocalPoolVar::setDataPoolId(lp_id_t poolId) { this->localPoolId = poolId; } template inline bool LocalPoolVar::isValid() const { return valid; } template inline void LocalPoolVar::setValid(bool validity) { this->valid = validity; } template inline uint8_t LocalPoolVar::getValid() const { return valid; } template inline ReturnValue_t LocalPoolVar::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 LocalPoolVar::getSerializedSize() const { return SerializeAdapter::getSerializedSize(&value); } template inline ReturnValue_t LocalPoolVar::deSerialize(const uint8_t** buffer, size_t* size, SerializeIF::Endianness streamEndianness) { return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); } template inline std::ostream& operator<< (std::ostream &out, const LocalPoolVar &var) { out << var.value; return out; } #endif