system_context_asio.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2022 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. #if defined(_MSC_VER)
  11. #pragma warning(push)
  12. #pragma warning(disable : 4251)
  13. #endif
  14. namespace rotor {
  15. namespace asio {
  16. namespace asio = boost::asio;
  17. struct supervisor_asio_t;
  18. /** \brief intrusive pointer for boost::asio supervisor */
  19. using supervisor_ptr_t = intrusive_ptr_t<supervisor_asio_t>;
  20. /** \struct system_context_asio_t
  21. * \brief The boost::asio system context, which holds a reference to
  22. * `boost::asio::io_context` and root supervisor
  23. */
  24. struct system_context_asio_t : public system_context_t {
  25. /** \brief intrusive pointer type for boost::asio system context */
  26. using ptr_t = rotor::intrusive_ptr_t<system_context_asio_t>;
  27. /** \brief construct the context from `boost::asio::io_context` reference */
  28. system_context_asio_t(asio::io_context &io_context_) : io_context{io_context_} {}
  29. /** \brief returns a reference to `boost::asio::io_context` */
  30. inline asio::io_context &get_io_context() noexcept { return io_context; }
  31. protected:
  32. friend struct supervisor_asio_t;
  33. /** \brief a reference to `boost::asio::io_context` */
  34. asio::io_context &io_context;
  35. };
  36. /** \brief intrusive pointer type for boost::asio system context */
  37. using system_context_ptr_t = typename system_context_asio_t::ptr_t;
  38. } // namespace asio
  39. } // namespace rotor
  40. #if defined(_MSC_VER)
  41. #pragma warning(pop)
  42. #endif