aop_pubrel.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2017-2023 zhllxt
  3. *
  4. * author : zhllxt
  5. * email : 37792738@qq.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 __ASIO2_MQTT_AOP_PUBREL_HPP__
  11. #define __ASIO2_MQTT_AOP_PUBREL_HPP__
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. #pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <asio2/base/iopool.hpp>
  16. #include <asio2/base/detail/function_traits.hpp>
  17. #include <asio2/base/detail/util.hpp>
  18. #include <asio2/mqtt/message.hpp>
  19. namespace asio2::detail
  20. {
  21. template<class caller_t, class args_t>
  22. class mqtt_aop_pubrel
  23. {
  24. friend caller_t;
  25. protected:
  26. // server or client
  27. template<class Message, class Response>
  28. inline void _before_pubrel_callback(
  29. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  30. Message& msg, Response& rep)
  31. {
  32. detail::ignore_unused(ec, caller_ptr, caller, om, msg, rep);
  33. using message_type [[maybe_unused]] = typename detail::remove_cvref_t<Message>;
  34. using response_type [[maybe_unused]] = typename detail::remove_cvref_t<Response>;
  35. rep.packet_id(msg.packet_id());
  36. // PUBCOMP Reason Code
  37. // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901154
  38. if constexpr (std::is_same_v<response_type, mqtt::v5::pubcomp>)
  39. {
  40. rep.reason_code(detail::to_underlying(mqtt::error::success));
  41. }
  42. else
  43. {
  44. std::ignore = true;
  45. }
  46. }
  47. // server or client
  48. inline void _before_user_callback_impl(
  49. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  50. mqtt::v3::pubrel& msg, asio2::mqtt::v3::pubcomp& rep)
  51. {
  52. if (_before_pubrel_callback(ec, caller_ptr, caller, om, msg, rep); ec)
  53. return;
  54. }
  55. // server or client
  56. inline void _before_user_callback_impl(
  57. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  58. mqtt::v4::pubrel& msg, asio2::mqtt::v4::pubcomp& rep)
  59. {
  60. if (_before_pubrel_callback(ec, caller_ptr, caller, om, msg, rep); ec)
  61. return;
  62. }
  63. // server or client
  64. inline void _before_user_callback_impl(
  65. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  66. mqtt::v5::pubrel& msg, asio2::mqtt::v5::pubcomp& rep)
  67. {
  68. if (_before_pubrel_callback(ec, caller_ptr, caller, om, msg, rep); ec)
  69. return;
  70. }
  71. inline void _after_user_callback_impl(
  72. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  73. mqtt::v3::pubrel& msg, asio2::mqtt::v3::pubcomp& rep)
  74. {
  75. detail::ignore_unused(ec, caller_ptr, caller, om, msg, rep);
  76. }
  77. inline void _after_user_callback_impl(
  78. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  79. mqtt::v4::pubrel& msg, asio2::mqtt::v4::pubcomp& rep)
  80. {
  81. detail::ignore_unused(ec, caller_ptr, caller, om, msg, rep);
  82. }
  83. inline void _after_user_callback_impl(
  84. error_code& ec, std::shared_ptr<caller_t>& caller_ptr, caller_t* caller, mqtt::message& om,
  85. mqtt::v5::pubrel& msg, asio2::mqtt::v5::pubcomp& rep)
  86. {
  87. detail::ignore_unused(ec, caller_ptr, caller, om, msg, rep);
  88. }
  89. };
  90. }
  91. #endif // !__ASIO2_MQTT_AOP_PUBREL_HPP__