improved error handling significantly
This commit is contained in:
parent
007526c050
commit
3be51762cc
@ -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 */
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
@ -179,9 +179,6 @@ protected:
|
||||
friend std::ostream& operator<< (std::ostream &out,
|
||||
const LocalPoolVariable<U> &var);
|
||||
#endif
|
||||
|
||||
private:
|
||||
void reportReadCommitError(bool read, object_id_t objectId, lp_id_t lpId);
|
||||
};
|
||||
|
||||
#include "LocalPoolVariable.tpp"
|
||||
|
@ -45,16 +45,20 @@ inline ReturnValue_t LocalPoolVariable<T>::readWithoutLock() {
|
||||
|
||||
PoolEntry<T>* 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<T>::commitWithoutLock() {
|
||||
}
|
||||
PoolEntry<T>* 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<T>::operator >(const T &other) const {
|
||||
return not (*this < other);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void LocalPoolVariable<T>::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_ */
|
||||
|
@ -44,12 +44,9 @@ inline ReturnValue_t LocalPoolVector<T, vectorSize>::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<T, vectorSize>::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<T>* 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());
|
||||
|
Loading…
Reference in New Issue
Block a user