#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ #error Include LocalPoolVector.h before LocalPoolVector.tpp! #endif template inline LocalPoolVector::LocalPoolVector( HasLocalDataPoolIF* hkOwner, lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} template inline LocalPoolVector::LocalPoolVector(object_id_t poolOwner, lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} template inline LocalPoolVector::LocalPoolVector(gp_id_t globalPoolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, dataSet, setReadWriteMode) {} template inline ReturnValue_t LocalPoolVector::read( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs); return readWithoutLock(); } template inline ReturnValue_t LocalPoolVector::readWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_WRITE) { object_id_t targetObjectId = hkManager->getOwner()->getObjectId(); reportReadCommitError("LocalPoolVector", PoolVariableIF::INVALID_READ_WRITE_MODE, true, targetObjectId, localPoolId); return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); memset(this->value, 0, vectorSize * sizeof(T)); if(result != RETURN_OK) { object_id_t targetObjectId = hkManager->getOwner()->getObjectId(); reportReadCommitError("LocalPoolVector", result, true, targetObjectId, localPoolId); return result; } std::memcpy(this->value, poolEntry->address, poolEntry->getByteSize()); this->valid = poolEntry->valid; return RETURN_OK; } template inline ReturnValue_t LocalPoolVector::commit(bool valid, MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { this->setValid(valid); return commit(timeoutType, timeoutMs); } template inline ReturnValue_t LocalPoolVector::commit( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs); return commitWithoutLock(); } template inline ReturnValue_t LocalPoolVector::commitWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_READ) { object_id_t targetObjectId = hkManager->getOwner()->getObjectId(); reportReadCommitError("LocalPoolVector", PoolVariableIF::INVALID_READ_WRITE_MODE, false, targetObjectId, localPoolId); return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK) { object_id_t targetObjectId = hkManager->getOwner()->getObjectId(); reportReadCommitError("LocalPoolVector", result, false, targetObjectId, localPoolId); return result; } std::memcpy(poolEntry->address, this->value, poolEntry->getByteSize()); poolEntry->valid = this->valid; return RETURN_OK; } template inline T& LocalPoolVector::operator [](size_t i) { if(i < vectorSize) { return value[i]; } // If this happens, I have to set some value. I consider this // a configuration error, but I wont exit here. #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "LocalPoolVector: Invalid index. Setting or returning" " last value!" << std::endl; #else fsfw::printError("LocalPoolVector: Invalid index. Setting or returning" " last value!\n\r"); #endif return value[vectorSize]; } template inline const T& LocalPoolVector::operator [](size_t i) const { if(i < vectorSize) { return value[i]; } // If this happens, I have to set some value. I consider this // a configuration error, but I wont exit here. #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "LocalPoolVector: Invalid index. Setting or returning" " last value!" << std::endl; #else fsfw::printError("LocalPoolVector: Invalid index. Setting or returning" " last value!\n\r"); #endif return value[vectorSize]; } template inline ReturnValue_t LocalPoolVector::serialize(uint8_t** buffer, size_t* size, size_t maxSize, SerializeIF::Endianness streamEndianness) const { ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; for (uint16_t i = 0; i < vectorSize; i++) { result = SerializeAdapter::serialize(&(value[i]), buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { break; } } return result; } template inline size_t LocalPoolVector::getSerializedSize() const { return vectorSize * SerializeAdapter::getSerializedSize(value); } template inline ReturnValue_t LocalPoolVector::deSerialize( const uint8_t** buffer, size_t* size, SerializeIF::Endianness streamEndianness) { ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; for (uint16_t i = 0; i < vectorSize; i++) { result = SerializeAdapter::deSerialize(&(value[i]), buffer, size, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { break; } } return result; } #if FSFW_CPP_OSTREAM_ENABLED == 1 template inline std::ostream& operator<< (std::ostream &out, const LocalPoolVector &var) { out << "Vector: ["; for(int i = 0;i < vectorSize; i++) { out << var.value[i]; if(i < vectorSize - 1) { out << ", "; } } out << "]"; return out; } #endif #endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ */