tristate_obj.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef SOPHIAR2_TRISTATE_OBJ_H
  2. #define SOPHIAR2_TRISTATE_OBJ_H
  3. #include "core/global_io_context.hpp"
  4. #include <coroutine>
  5. #include <memory>
  6. #include <boost/asio/awaitable.hpp>
  7. #include <boost/core/noncopyable.hpp>
  8. namespace sophiar {
  9. template<typename FreqTag>
  10. class tristate_obj : public use_context<FreqTag>, private boost::noncopyable {
  11. public:
  12. enum class state_type {
  13. INITIAL,
  14. INITIALIZING,
  15. RESETTING,
  16. PENDING,
  17. STARTING,
  18. STOPPING,
  19. RUNNING,
  20. };
  21. tristate_obj();
  22. virtual ~tristate_obj();
  23. boost::asio::awaitable<bool> init();
  24. boost::asio::awaitable<bool> start();
  25. boost::asio::awaitable<void> stop();
  26. boost::asio::awaitable<void> reset();
  27. state_type get_state() const;
  28. protected:
  29. virtual boost::asio::awaitable<bool> on_init() { co_return true; } // TODO add no_throw
  30. virtual boost::asio::awaitable<bool> on_start() { co_return true; }
  31. virtual boost::asio::awaitable<void> on_stop() { co_return; }
  32. virtual boost::asio::awaitable<void> on_reset() { co_return; }
  33. private:
  34. struct impl;
  35. std::unique_ptr<impl> pimpl;
  36. };
  37. }
  38. #endif //SOPHIAR2_TRISTATE_OBJ_H