simple.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include "task.h"
  3. namespace NRainCheck {
  4. class ISimpleTask;
  5. // Function called on continue
  6. class TContinueFunc {
  7. friend class TSimpleTaskRunner;
  8. typedef TContinueFunc (ISimpleTask::*TFunc)();
  9. TFunc Func;
  10. public:
  11. TContinueFunc()
  12. : Func(nullptr)
  13. {
  14. }
  15. TContinueFunc(void*)
  16. : Func(nullptr)
  17. {
  18. }
  19. template <typename TTask>
  20. TContinueFunc(TContinueFunc (TTask::*func)())
  21. : Func((TFunc)func)
  22. {
  23. static_assert((std::is_base_of<ISimpleTask, TTask>::value), "expect (std::is_base_of<ISimpleTask, TTask>::value)");
  24. }
  25. bool operator!() const {
  26. return !Func;
  27. }
  28. };
  29. class TSimpleTaskRunner: public TTaskRunnerBase {
  30. public:
  31. TSimpleTaskRunner(IEnv* env, ISubtaskListener* parentTask, TAutoPtr<ISimpleTask>);
  32. ~TSimpleTaskRunner() override;
  33. private:
  34. // Function to be called on completion of all pending tasks.
  35. TContinueFunc ContinueFunc;
  36. bool ReplyReceived() override /* override */;
  37. ISimpleTask* GetImpl() {
  38. return (ISimpleTask*)GetImplBase();
  39. }
  40. };
  41. class ISimpleTask: public ITaskBase {
  42. public:
  43. typedef TSimpleTaskRunner TTaskRunner;
  44. typedef ISimpleTask ITask;
  45. virtual TContinueFunc Start() = 0;
  46. };
  47. }