system_context_asio.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2020 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  4. //
  5. // Distributed under the MIT Software License
  6. //
  7. #include "rotor/arc.hpp"
  8. #include "rotor/system_context.h"
  9. #include <boost/asio.hpp>
  10. namespace rotor {
  11. namespace asio {
  12. namespace asio = boost::asio;
  13. struct supervisor_asio_t;
  14. /** \brief intrusive pointer for boost::asio supervisor */
  15. using supervisor_ptr_t = intrusive_ptr_t<supervisor_asio_t>;
  16. /** \struct system_context_asio_t
  17. * \brief The boost::asio system context, which holds a reference to
  18. * `boost::asio::io_context` and root supervisor
  19. */
  20. struct system_context_asio_t : public system_context_t {
  21. /** \brief intrusive pointer type for boost::asio system context */
  22. using ptr_t = rotor::intrusive_ptr_t<system_context_asio_t>;
  23. /** \brief construct the context from `boost::asio::io_context` reference */
  24. system_context_asio_t(asio::io_context &io_context_) : io_context{io_context_} {}
  25. /** \brief returns a reference to `boost::asio::io_context` */
  26. inline asio::io_context &get_io_context() noexcept { return io_context; }
  27. protected:
  28. friend struct supervisor_asio_t;
  29. /** \brief a reference to `boost::asio::io_context` */
  30. asio::io_context &io_context;
  31. };
  32. /** \brief intrusive pointer type for boost::asio system context */
  33. using system_context_ptr_t = typename system_context_asio_t::ptr_t;
  34. } // namespace asio
  35. } // namespace rotor