cleaned up a bit

This commit is contained in:
Robin Müller 2021-05-31 12:30:54 +02:00
parent e961f3f038
commit 54e60f4ddc
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 20 additions and 25 deletions

View File

@ -204,11 +204,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
return MessageQueueIF::EMPTY;
case EBADF: {
//mqdes doesn't represent a valid queue open for reading.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receive: configuration error "
<< strerror(errno) << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
return handleRecvError("EBADF");
}
case EINVAL: {
/*
@ -220,11 +216,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
* queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't
* been set in the queue's mq_flags.
*/
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receive: EINVAL error "
<< strerror(errno) << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
return handleRecvError("EINVAL");
}
case EMSGSIZE: {
/*
@ -236,28 +228,16 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
* given msg_len is too short for the message that would have
* been received.
*/
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receive: EMSGSIZE error "
<< strerror(errno) << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
return handleRecvError("EMSGSIZE");
}
case EINTR: {
//The operation was interrupted by a signal.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receiveMessage: EINTR error " << strerror(errno) <<
std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
return handleRecvError("EINTR");
}
case ETIMEDOUT: {
//The operation was interrupted by a signal.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receiveMessage: ETIMEDOUT error " << strerror(errno) <<
std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
return handleRecvError("ETIMEDOUT");
}
default:
@ -423,3 +403,17 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t MessageQueue::handleRecvError(const char * const failString) {
if(failString == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receiveMessage: " << failString << " error "
<< strerror(errno) << std::endl;
#else
sif::printError("MessageQueue::receiveMessage: %s error %s\n", failString,
strerror(errno));
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -182,6 +182,7 @@ private:
const size_t maxMessageSize;
ReturnValue_t handleError(mq_attr* attributes, uint32_t messageDepth);
ReturnValue_t handleRecvError(const char* const failString);
};
#endif /* FSFW_OSAL_LINUX_MESSAGEQUEUE_H_ */