logger_traits.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // Copyright (c) 2023-2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MQTT5_LOGGER_TRAITS_HPP
  8. #define BOOST_MQTT5_LOGGER_TRAITS_HPP
  9. #include <boost/mqtt5/property_types.hpp>
  10. #include <boost/mqtt5/reason_codes.hpp>
  11. #include <boost/mqtt5/types.hpp>
  12. #include <boost/asio/ip/tcp.hpp>
  13. #include <boost/system/error_code.hpp>
  14. #include <boost/type_traits/is_detected.hpp>
  15. #include <iostream>
  16. #include <string_view>
  17. #include <type_traits>
  18. namespace boost::mqtt5 {
  19. namespace asio = boost::asio;
  20. using boost::system::error_code;
  21. // NOOP Logger
  22. class noop_logger {};
  23. // at_resolve
  24. template <typename T>
  25. using at_resolve_sig = decltype(
  26. std::declval<T&>().at_resolve(
  27. std::declval<error_code>(),
  28. std::declval<std::string_view>(), std::declval<std::string_view>(),
  29. std::declval<const asio::ip::tcp::resolver::results_type&>()
  30. )
  31. );
  32. template <typename T>
  33. constexpr bool has_at_resolve = boost::is_detected<at_resolve_sig, T>::value;
  34. // at_tcp_connect
  35. template <typename T>
  36. using at_tcp_connect_sig = decltype(
  37. std::declval<T&>().at_tcp_connect(
  38. std::declval<error_code>(), std::declval<asio::ip::tcp::endpoint>()
  39. )
  40. );
  41. template <typename T>
  42. constexpr bool has_at_tcp_connect = boost::is_detected<at_tcp_connect_sig, T>::value;
  43. // at_tls_handshake
  44. template <typename T>
  45. using at_tls_handshake_sig = decltype(
  46. std::declval<T&>().at_tls_handshake(
  47. std::declval<error_code>(), std::declval<asio::ip::tcp::endpoint>()
  48. )
  49. );
  50. template <typename T>
  51. constexpr bool has_at_tls_handshake = boost::is_detected<at_tls_handshake_sig, T>::value;
  52. // at_ws_handshake
  53. template <typename T>
  54. using at_ws_handshake_sig = decltype(
  55. std::declval<T&>().at_ws_handshake(
  56. std::declval<error_code>(), std::declval<asio::ip::tcp::endpoint>()
  57. )
  58. );
  59. template <typename T>
  60. constexpr bool has_at_ws_handshake = boost::is_detected<at_ws_handshake_sig, T>::value;
  61. // at_connack
  62. template <typename T>
  63. using at_connack_sig = decltype(
  64. std::declval<T&>().at_connack(
  65. std::declval<reason_code>(),
  66. std::declval<bool>(), std::declval<const connack_props&>()
  67. )
  68. );
  69. template <typename T>
  70. constexpr bool has_at_connack = boost::is_detected<at_connack_sig, T>::value;
  71. // at_disconnect
  72. template <typename T>
  73. using at_disconnect_sig = decltype(
  74. std::declval<T&>().at_disconnect(
  75. std::declval<reason_code>(), std::declval<const disconnect_props&>()
  76. )
  77. );
  78. template <typename T>
  79. constexpr bool has_at_disconnect = boost::is_detected<at_disconnect_sig, T>::value;
  80. // at_transport_error
  81. template <typename T>
  82. using at_transport_error = decltype(
  83. std::declval<T&>().at_transport_error(std::declval<error_code>())
  84. );
  85. template <typename T>
  86. constexpr bool has_at_transport_error = boost::is_detected<at_transport_error, T>::value;
  87. } // end namespace boost::mqtt5
  88. #endif // !BOOST_MQTT5_LOGGER_TRAITS_HPP