channel_handler.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // experimental/detail/channel_handler.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP
  11. #define ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/associator.hpp"
  17. #include "asio/experimental/detail/channel_payload.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace experimental {
  21. namespace detail {
  22. template <typename Payload, typename Handler>
  23. class channel_handler
  24. {
  25. public:
  26. channel_handler(ASIO_MOVE_ARG(Payload) p, Handler& h)
  27. : payload_(ASIO_MOVE_CAST(Payload)(p)),
  28. handler_(ASIO_MOVE_CAST(Handler)(h))
  29. {
  30. }
  31. void operator()()
  32. {
  33. payload_.receive(handler_);
  34. }
  35. //private:
  36. Payload payload_;
  37. Handler handler_;
  38. };
  39. } // namespace detail
  40. } // namespace experimental
  41. template <template <typename, typename> class Associator,
  42. typename Payload, typename Handler, typename DefaultCandidate>
  43. struct associator<Associator,
  44. experimental::detail::channel_handler<Payload, Handler>,
  45. DefaultCandidate>
  46. : Associator<Handler, DefaultCandidate>
  47. {
  48. static typename Associator<Handler, DefaultCandidate>::type get(
  49. const experimental::detail::channel_handler<Payload, Handler>& h,
  50. const DefaultCandidate& c = DefaultCandidate()) ASIO_NOEXCEPT
  51. {
  52. return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
  53. }
  54. };
  55. } // namespace asio
  56. #include "asio/detail/pop_options.hpp"
  57. #endif // ASIO_EXPERIMENTAL_DETAIL_CHANNEL_HANDLER_HPP