| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifndef SOPHIAR2_TRISTATE_OBJ_H
- #define SOPHIAR2_TRISTATE_OBJ_H
- #include "core/global_io_context.hpp"
- #include <coroutine>
- #include <memory>
- #include <boost/asio/awaitable.hpp>
- #include <boost/core/noncopyable.hpp>
- namespace sophiar {
- template<typename FreqTag>
- class tristate_obj : public use_context<FreqTag>, private boost::noncopyable {
- public:
- enum class state_type {
- INITIAL,
- INITIALIZING,
- RESETTING,
- PENDING,
- STARTING,
- STOPPING,
- RUNNING,
- };
- tristate_obj();
- virtual ~tristate_obj();
- boost::asio::awaitable<bool> init();
- boost::asio::awaitable<bool> start();
- boost::asio::awaitable<void> stop();
- boost::asio::awaitable<void> reset();
- state_type get_state() const;
- protected:
- virtual boost::asio::awaitable<bool> on_init() { co_return true; } // TODO add no_throw
- virtual boost::asio::awaitable<bool> on_start() { co_return true; }
- virtual boost::asio::awaitable<void> on_stop() { co_return; }
- virtual boost::asio::awaitable<void> on_reset() { co_return; }
- private:
- struct impl;
- std::unique_ptr<impl> pimpl;
- };
- }
- #endif //SOPHIAR2_TRISTATE_OBJ_H
|