From 3be51762cccb8964ab3d19e379f1d427a99710b7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 7 Jan 2021 20:23:23 +0100 Subject: [PATCH] improved error handling significantly --- datapoollocal/LocalPoolObjectBase.cpp | 41 +++++++++++++++++++++++++++ datapoollocal/LocalPoolObjectBase.h | 2 ++ datapoollocal/LocalPoolVariable.h | 3 -- datapoollocal/LocalPoolVariable.tpp | 41 +++++++-------------------- datapoollocal/LocalPoolVector.tpp | 23 +++++++-------- 5 files changed, 64 insertions(+), 46 deletions(-) diff --git a/datapoollocal/LocalPoolObjectBase.cpp b/datapoollocal/LocalPoolObjectBase.cpp index 4b57dede..b84569b8 100644 --- a/datapoollocal/LocalPoolObjectBase.cpp +++ b/datapoollocal/LocalPoolObjectBase.cpp @@ -79,3 +79,44 @@ bool LocalPoolObjectBase::hasChanged() const { void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) { this->readWriteMode = newReadWriteMode; } + +void LocalPoolObjectBase::reportReadCommitError(const char* variableType, + ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId) { +#if FSFW_DISABLE_PRINTOUT == 0 + const char* type = nullptr; + if(read) { + type = "read"; + } + else { + type = "commit"; + } + + const char* errMsg = nullptr; + if(error == HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND) { + errMsg = "Pool entry not found"; + } + else if(error == HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT) { + errMsg = "Pool entry type conflict"; + } + else if(error == PoolVariableIF::INVALID_READ_WRITE_MODE) { + errMsg = "Pool variable wrong read-write mode"; + } + else if(error == PoolVariableIF::INVALID_POOL_ENTRY) { + errMsg = "Pool entry invalid"; + } + else { + errMsg = "Unknown error code"; + } + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << variableType << ": " << type << " call | " << errMsg + << " | Owner: " << std::hex << std::setw(8) + << std::setfill('0') << objectId << " LPID: 0x" << lpId + << std::dec << 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 */ +#endif /* FSFW_DISABLE_PRINTOUT == 0 */ +} diff --git a/datapoollocal/LocalPoolObjectBase.h b/datapoollocal/LocalPoolObjectBase.h index 7165fc24..25ca594d 100644 --- a/datapoollocal/LocalPoolObjectBase.h +++ b/datapoollocal/LocalPoolObjectBase.h @@ -56,6 +56,8 @@ protected: //! @brief Pointer to the class which manages the HK pool. LocalDataPoolManager* hkManager; + void reportReadCommitError(const char* variableType, + ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId); }; diff --git a/datapoollocal/LocalPoolVariable.h b/datapoollocal/LocalPoolVariable.h index ca0aede9..22019c2f 100644 --- a/datapoollocal/LocalPoolVariable.h +++ b/datapoollocal/LocalPoolVariable.h @@ -179,9 +179,6 @@ protected: friend std::ostream& operator<< (std::ostream &out, const LocalPoolVariable &var); #endif - -private: - void reportReadCommitError(bool read, object_id_t objectId, lp_id_t lpId); }; #include "LocalPoolVariable.tpp" diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index c20e9230..4d472c31 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -45,16 +45,20 @@ inline ReturnValue_t LocalPoolVariable::readWithoutLock() { PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); - if(result != RETURN_OK or poolEntry == nullptr) { + if(result != RETURN_OK) { object_id_t ownerObjectId = hkManager->getOwner()->getObjectId(); - reportReadCommitError(true, ownerObjectId, localPoolId); + reportReadCommitError("LocalPoolVariable", result, + false, ownerObjectId, localPoolId); return result; } + // Actually this should never happen.. if(poolEntry->address == nullptr) { + result = PoolVariableIF::INVALID_POOL_ENTRY; object_id_t ownerObjectId = hkManager->getOwner()->getObjectId(); - reportReadCommitError(true, ownerObjectId, localPoolId); - return PoolVariableIF::INVALID_POOL_ENTRY; + reportReadCommitError("LocalPoolVariable", result, + false, ownerObjectId, localPoolId); + return result; } this->value = *(poolEntry->address); @@ -90,9 +94,10 @@ inline ReturnValue_t LocalPoolVariable::commitWithoutLock() { } PoolEntry* poolEntry = nullptr; ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); - if(result != RETURN_OK or poolEntry == nullptr) { + if(result != RETURN_OK) { object_id_t ownerObjectId = hkManager->getOwner()->getObjectId(); - reportReadCommitError(false, ownerObjectId, localPoolId); + reportReadCommitError("LocalPoolVariable", result, + false, ownerObjectId, localPoolId); return result; } @@ -195,28 +200,4 @@ inline bool LocalPoolVariable::operator >(const T &other) const { return not (*this < other); } -template -inline void LocalPoolVariable::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 */ -} - - #endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */ diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index 6af80de6..99e37a87 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -44,12 +44,9 @@ inline ReturnValue_t LocalPoolVector::readWithoutLock() { memset(this->value, 0, vectorSize * sizeof(T)); if(result != RETURN_OK) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "LocalPoolVector: 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; -#endif + object_id_t targetObjectId = hkManager->getOwner()->getObjectId(); + reportReadCommitError("LocalPoolVector", result, true, targetObjectId, + localPoolId); return result; } std::memcpy(this->value, poolEntry->address, poolEntry->getByteSize()); @@ -69,19 +66,19 @@ inline ReturnValue_t LocalPoolVector::commitWithoutLock() { if(readWriteMode == pool_rwm_t::VAR_READ) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LocalPoolVector: Invalid read write " - "mode for commit() call." << std::endl; + "mode for commit call." << std::endl; +#else + sif::warning << "LocalPoolVector: Invalid read write " + "mode for commit call." << std::endl; #endif 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 << "LocalPoolVector: Read of local pool variable of object " - << std::hex << std::setw(8) << std::setfill('0') - << hkManager->getOwner() << " and lp ID " << localPoolId - << std::dec << " failed." << std::endl; -#endif + object_id_t targetObjectId = hkManager->getOwner()->getObjectId(); + reportReadCommitError("LocalPoolVector", result, true, targetObjectId, + localPoolId); return result; } std::memcpy(poolEntry->address, this->value, poolEntry->getByteSize());