#ifndef INTERNALTASK_H_
#define INTERNALTASK_H_
+#include <functional>
#include <msp/core/thread.h>
#include "task.h"
+/**
+Runs a worker thread. Tools should derive a thread class from
+InternalTask::Worker. The worker thread must set its status to either SUCCESS
+or ERROR before terminating.
+*/
class InternalTask: public Task
{
-public:
+private:
class Worker: public Msp::Thread
{
friend class InternalTask;
- protected:
- Status status;
-
- Worker();
+ private:
+ std::function<bool()> func;
+ volatile Status status = Task::RUNNING;
public:
+ Worker(std::function<bool()> f): func(f) { }
+
Status get_status() const { return status; }
+
+ private:
+ void main() override;
};
-private:
- Worker *worker;
+ Worker worker;
public:
- InternalTask(Worker *);
+ InternalTask(std::function<bool()> f): worker(f) { }
~InternalTask();
- virtual void start();
- virtual Status check();
+ std::string get_command() const override { return "<internal>"; }
+ void start() override;
+ Status check() override;
+ Status wait() override;
};
#endif