2020-08-13 20:53:35 +02:00
|
|
|
#include "../../ipc/QueueFactory.h"
|
2020-11-17 19:25:57 +01:00
|
|
|
#include "../../ipc/MessageQueueSenderIF.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
#include "MessageQueue.h"
|
|
|
|
#include "RtemsBasic.h"
|
|
|
|
|
2020-11-17 19:35:37 +01:00
|
|
|
QueueFactory* QueueFactory::factoryInstance = nullptr;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
|
2020-11-17 19:25:57 +01:00
|
|
|
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,bool ignoreFault) {
|
2019-08-28 14:50:24 +02:00
|
|
|
//TODO add ignoreFault functionality
|
2018-07-12 16:29:32 +02:00
|
|
|
message->setSender(sentFrom);
|
|
|
|
rtems_status_code result = rtems_message_queue_send(sendTo, message->getBuffer(),
|
2020-11-17 19:25:57 +01:00
|
|
|
message->getMessageSize());
|
2018-07-13 18:28:26 +02:00
|
|
|
switch(result){
|
|
|
|
case RTEMS_SUCCESSFUL:
|
|
|
|
//message sent successfully
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
case RTEMS_INVALID_ID:
|
|
|
|
//invalid queue id
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
case RTEMS_INVALID_SIZE:
|
|
|
|
// invalid message size
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
case RTEMS_INVALID_ADDRESS:
|
|
|
|
//buffer is NULL
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
case RTEMS_UNSATISFIED:
|
|
|
|
//out of message buffers
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
case RTEMS_TOO_MANY:
|
|
|
|
//queue's limit has been reached
|
|
|
|
return MessageQueueIF::FULL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QueueFactory* QueueFactory::instance() {
|
2020-11-17 19:35:37 +01:00
|
|
|
if (factoryInstance == nullptr) {
|
2018-07-12 16:29:32 +02:00
|
|
|
factoryInstance = new QueueFactory;
|
|
|
|
}
|
|
|
|
return factoryInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueFactory::QueueFactory() {
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueFactory::~QueueFactory() {
|
|
|
|
}
|
|
|
|
|
2020-06-06 15:47:33 +02:00
|
|
|
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
|
|
|
|
size_t maxMessageSize) {
|
|
|
|
return new MessageQueue(messageDepth, maxMessageSize);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
|
|
|
|
delete queue;
|
|
|
|
}
|