utility: Sending Messages via TaskScheduler by default

This change makes the MessageQueue use Tasks for sending a Message to each MessageListener. Messages can define their
behavior by setting setSendAsTask(), the default is true. Only MessageStatus and MessageInterruptTasks are still sent on
the Messaging thread to allow for immediate effect.

This change also introduced the class SimpleTask which holds only a single perform() callback to override, for Tasks
that are finished in a single step. The class LambdaTask derives from SimpleTask and allows for passing a lambda as the
perform() callback.
This commit is contained in:
Eberhard Graether
2015-04-26 22:21:01 +02:00
parent d1db054d98
commit e0ddc67597
21 changed files with 233 additions and 146 deletions
+15
View File
@@ -0,0 +1,15 @@
#include "utility/scheduling/LambdaTask.h"
LambdaTask::LambdaTask(std::function<void()> func)
: m_func(func)
{
}
LambdaTask::~LambdaTask()
{
}
void LambdaTask::perform()
{
m_func();
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef LAMBDA_TASK_H
#define LAMBDA_TASK_H
#include <functional>
#include "utility/scheduling/SimpleTask.h"
class LambdaTask
: public SimpleTask
{
public:
LambdaTask(std::function<void()> func);
virtual ~LambdaTask();
virtual void perform();
private:
std::function<void()> m_func;
};
#endif // LAMBDA_TASK_H
+28
View File
@@ -0,0 +1,28 @@
#include "utility/scheduling/SimpleTask.h"
void SimpleTask::enter()
{
}
Task::TaskState SimpleTask::update()
{
perform();
return Task::STATE_FINISHED;
}
void SimpleTask::exit()
{
}
void SimpleTask::interrupt()
{
}
void SimpleTask::revert()
{
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef SIMPLE_TASK_H
#define SIMPLE_TASK_H
#include "utility/scheduling/Task.h"
class SimpleTask
: public Task
{
public:
virtual void enter();
virtual TaskState update();
virtual void exit();
virtual void interrupt();
virtual void revert();
virtual void perform() = 0;
};
#endif // SIMPLE_TASK_H