Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Executable.hxx
Go to the documentation of this file.
1
35#ifndef _EXECUTOR_EXECUTABLE_HXX_
36#define _EXECUTOR_EXECUTABLE_HXX_
37
39#include "utils/QMember.hxx"
40
42class Executable : public Notifiable, public QMember
43{
44public:
45 virtual ~Executable();
46
47 void test_deletion();
48
51 virtual void run() = 0;
52
56 void notify() override {
57 HASSERT(0 && "unexpected call to notify in Executable");
58 }
59
63 virtual void alloc_result(QMember *item)
64 {
65 HASSERT(0 && "unexpected call to alloc_result");
66 }
67};
68
72{
73public:
76 CallbackExecutable(std::function<void()> &&body)
77 : body_(std::move(body))
78 {
79 }
80
82 void run() override
83 {
84 body_();
85 delete this;
86 }
87
88private:
90 std::function<void()> body_;
91};
92
93#endif // _EXECUTOR_EXECUTABLE_HXX_
A notifiable class that calls a particular function object once when it is invoked,...
void run() override
Calls the notification method.
std::function< void()> body_
Function object (callback) to call.
CallbackExecutable(std::function< void()> &&body)
Constructor.
An object that can be scheduled on an executor to run.
virtual void run()=0
Entry point.
virtual void alloc_result(QMember *item)
Return the result of an alloc_async() from a memory Pool.
void notify() override
Crashes the program – everyone who is expecting notify calls must override this function.
An object that can schedule itself on an executor to run.
Essentially a "next" pointer container.
Definition QMember.hxx:42
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138