]> git.tdb.fi Git - builder.git/blob - source/lib/internaltask.h
Add visibility decorations to the library and plugins
[builder.git] / source / lib / internaltask.h
1 #ifndef INTERNALTASK_H_
2 #define INTERNALTASK_H_
3
4 #include <functional>
5 #include <msp/core/thread.h>
6 #include "libbuilder_api.h"
7 #include "task.h"
8
9 /**
10 Runs a worker thread.  Tools should derive a thread class from
11 InternalTask::Worker.  The worker thread must set its status to either SUCCESS
12 or ERROR before terminating.
13 */
14 class LIBBUILDER_API InternalTask: public Task
15 {
16 private:
17         class LIBBUILDER_API Worker: public Msp::Thread
18         {
19                 friend class InternalTask;
20
21         private:
22                 std::function<bool()> func;
23                 volatile Status status = Task::RUNNING;
24
25         public:
26                 Worker(std::function<bool()> f): func(f) { }
27
28                 Status get_status() const { return status; }
29
30         private:
31                 void main() override;
32         };
33
34         Worker worker;
35
36 public:
37         InternalTask(std::function<bool()> f): worker(f) { }
38         ~InternalTask();
39
40         std::string get_command() const override { return "<internal>"; }
41         void start() override;
42         Status check() override;
43         Status wait() override;
44 };
45
46 #endif