WIP: somethings wrong.. #19
@ -11,7 +11,8 @@
|
||||
|
||||
MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
|
||||
id(MessageQueueIF::NO_QUEUE),lastPartner(MessageQueueIF::NO_QUEUE),
|
||||
defaultDestination(MessageQueueIF::NO_QUEUE) {
|
||||
defaultDestination(MessageQueueIF::NO_QUEUE),
|
||||
maxMessageSize(maxMessageSize) {
|
||||
//debug << "MessageQueue::MessageQueue: Creating a queue" << std::endl;
|
||||
mq_attr attributes;
|
||||
this->id = 0;
|
||||
@ -142,6 +143,19 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
|
||||
if(message == nullptr) {
|
||||
sif::error << "MessageQueue::receiveMessage: Message is "
|
||||
"nullptr!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(message->getMaximumMessageSize() < maxMessageSize) {
|
||||
sif::error << "MessageQueue::receiveMessage: Message size "
|
||||
<< message->getMaximumMessageSize() <<
|
||||
" too small to receive data!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
unsigned int messagePriority = 0;
|
||||
int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()),
|
||||
message->getMaximumMessageSize(),&messagePriority);
|
||||
@ -258,18 +272,20 @@ void MessageQueue::setDefaultDestination(MessageQueueId_t defaultDestination) {
|
||||
this->defaultDestination = defaultDestination;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
return sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault);
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||
return sendMessageFrom(defaultDestination, message, sentFrom, ignoreFault);
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
return sendMessageFromMessageQueue(sendTo,message, maxMessageSize,
|
||||
sentFrom,ignoreFault);
|
||||
|
||||
}
|
||||
|
||||
MessageQueueId_t MessageQueue::getDefaultDestination() const {
|
||||
return this->defaultDestination;
|
||||
}
|
||||
@ -281,8 +297,22 @@ bool MessageQueue::isDefaultDestinationSet() const {
|
||||
uint16_t MessageQueue::queueCounter = 0;
|
||||
|
||||
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF *message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
MessageQueueMessageIF *message, size_t maxSize,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||
if(message == nullptr) {
|
||||
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message is "
|
||||
"nullptr!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(message->getMaximumMessageSize() > maxSize) {
|
||||
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message size "
|
||||
<< message->getMaximumMessageSize() << " too large for queue"
|
||||
" with max. message size " << maxSize << "!"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
message->setSender(sentFrom);
|
||||
int result = mq_send(sendTo,
|
||||
reinterpret_cast<const char*>(message->getBuffer()),
|
||||
|
@ -149,7 +149,8 @@ protected:
|
||||
* \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
|
||||
*/
|
||||
static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
|
||||
MessageQueueMessageIF* message, size_t maxSize,
|
||||
MessageQueueId_t sentFrom = NO_QUEUE,
|
||||
bool ignoreFault=false);
|
||||
private:
|
||||
/**
|
||||
@ -176,9 +177,10 @@ private:
|
||||
/**
|
||||
* The name of the message queue, stored for unlinking
|
||||
*/
|
||||
char name[5];
|
||||
char name[16];
|
||||
|
||||
static uint16_t queueCounter;
|
||||
const size_t maxMessageSize;
|
||||
|
||||
ReturnValue_t handleError(mq_attr* attributes, uint32_t messageDepth);
|
||||
};
|
||||
|
@ -31,10 +31,11 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object,
|
||||
"it implements ExecutableObjectIF" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back(newObject);
|
||||
|
||||
if(setTaskIF) {
|
||||
newObject->setTaskIF(this);
|
||||
}
|
||||
objectList.push_back(newObject);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -43,14 +44,14 @@ ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::startTask(void){
|
||||
ReturnValue_t PeriodicPosixTask::startTask(void) {
|
||||
started = true;
|
||||
//sif::info << stackSize << std::endl;
|
||||
PosixThread::createTask(&taskEntryPoint,this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void PeriodicPosixTask::taskFunctionality(void){
|
||||
void PeriodicPosixTask::taskFunctionality(void) {
|
||||
if(!started){
|
||||
suspend();
|
||||
}
|
||||
@ -64,14 +65,15 @@ void PeriodicPosixTask::taskFunctionality(void){
|
||||
if(!PosixThread::delayUntil(&lastWakeTime,periodMs)){
|
||||
char name[20] = {0};
|
||||
int status = pthread_getname_np(pthread_self(),name,sizeof(name));
|
||||
if(status==0){
|
||||
if(status == 0){
|
||||
sif::error << "PeriodicPosixTask " << name << ": Deadline "
|
||||
"missed." << std::endl;
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
sif::error << "PeriodicPosixTask X: Deadline missed. " <<
|
||||
status << std::endl;
|
||||
}
|
||||
if (this->deadlineMissedFunc != NULL) {
|
||||
if (this->deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
* The address of the task object is passed as an argument
|
||||
* to the system call.
|
||||
*/
|
||||
ReturnValue_t startTask(void);
|
||||
ReturnValue_t startTask(void) override;
|
||||
/**
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added.
|
||||
@ -42,9 +42,9 @@ public:
|
||||
ReturnValue_t addComponent(object_id_t object,
|
||||
bool setTaskIF = true) override;
|
||||
|
||||
uint32_t getPeriodMs() const;
|
||||
uint32_t getPeriodMs() const override;
|
||||
|
||||
ReturnValue_t sleepFor(uint32_t ms);
|
||||
ReturnValue_t sleepFor(uint32_t ms) override;
|
||||
|
||||
private:
|
||||
typedef std::vector<ExecutableObjectIF*> ObjectList; //!< Typedef for the List of objects.
|
||||
|
@ -9,10 +9,10 @@ QueueFactory* QueueFactory::factoryInstance = nullptr;
|
||||
|
||||
|
||||
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
MessageQueueMessageIF* message, size_t maxSize,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||
return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
|
||||
sentFrom,ignoreFault);
|
||||
maxSize, sentFrom,ignoreFault);
|
||||
}
|
||||
|
||||
QueueFactory* QueueFactory::instance() {
|
||||
|
Loading…
Reference in New Issue
Block a user