aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/rain_check/core/simple.h
blob: 82664cababdaac93b9733627ef7cbbdaadebd67e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "task.h"

namespace NRainCheck {
    class ISimpleTask;

    // Function called on continue
    class TContinueFunc {
        friend class TSimpleTaskRunner;

        typedef TContinueFunc (ISimpleTask::*TFunc)();
        TFunc Func;

    public:
        TContinueFunc()
            : Func(nullptr)
        { 
        } 

        TContinueFunc(void*)
            : Func(nullptr)
        { 
        } 

        template <typename TTask>
        TContinueFunc(TContinueFunc (TTask::*func)())
            : Func((TFunc)func) 
        {
            static_assert((std::is_base_of<ISimpleTask, TTask>::value), "expect (std::is_base_of<ISimpleTask, TTask>::value)");
        }

        bool operator!() const {
            return !Func;
        }
    };

    class TSimpleTaskRunner: public TTaskRunnerBase {
    public:
        TSimpleTaskRunner(IEnv* env, ISubtaskListener* parentTask, TAutoPtr<ISimpleTask>);
        ~TSimpleTaskRunner() override;

    private:
        // Function to be called on completion of all pending tasks.
        TContinueFunc ContinueFunc;

        bool ReplyReceived() override /* override */;

        ISimpleTask* GetImpl() { 
            return (ISimpleTask*)GetImplBase(); 
        } 
    };

    class ISimpleTask: public ITaskBase {
    public:
        typedef TSimpleTaskRunner TTaskRunner;
        typedef ISimpleTask ITask;

        virtual TContinueFunc Start() = 0;
    };

}