Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:38:19

0001 //
0002 // Copyright (c) 2023-2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MQTT5_LOG_INVOKE_HPP
0009 #define BOOST_MQTT5_LOG_INVOKE_HPP
0010 
0011 #include <boost/mqtt5/logger_traits.hpp>
0012 #include <boost/mqtt5/property_types.hpp>
0013 #include <boost/mqtt5/reason_codes.hpp>
0014 #include <boost/mqtt5/types.hpp>
0015 
0016 #include <boost/asio/ip/tcp.hpp>
0017 #include <boost/system/error_code.hpp>
0018 
0019 #include <string_view>
0020 #include <type_traits>
0021 
0022 namespace boost::mqtt5::detail {
0023 
0024 namespace asio = boost::asio;
0025 using boost::system::error_code;
0026 
0027 template <typename LoggerType>
0028 class log_invoke {
0029     LoggerType _logger;
0030 public:
0031     explicit log_invoke(LoggerType logger = {}) :
0032         _logger(std::move(logger))
0033     {}
0034 
0035     void at_resolve(
0036         error_code ec, std::string_view host, std::string_view port,
0037         const asio::ip::tcp::resolver::results_type& eps
0038     ) {
0039         if constexpr (has_at_resolve<LoggerType>)
0040             _logger.at_resolve(ec, host, port, eps);
0041     }
0042 
0043     void at_tcp_connect(error_code ec, asio::ip::tcp::endpoint ep) {
0044         if constexpr (has_at_tcp_connect<LoggerType>)
0045             _logger.at_tcp_connect(ec, ep);
0046     }
0047 
0048     void at_tls_handshake(error_code ec, asio::ip::tcp::endpoint ep) {
0049         if constexpr (has_at_tls_handshake<LoggerType>)
0050             _logger.at_tls_handshake(ec, ep);
0051     }
0052 
0053     void at_ws_handshake(error_code ec, asio::ip::tcp::endpoint ep) {
0054         if constexpr (has_at_ws_handshake<LoggerType>)
0055             _logger.at_ws_handshake(ec, ep);
0056     }
0057 
0058     void at_connack(
0059         reason_code rc,
0060         bool session_present, const connack_props& ca_props
0061     ) {
0062         if constexpr (has_at_connack<LoggerType>)
0063             _logger.at_connack(rc, session_present, ca_props);
0064     }
0065 
0066     void at_disconnect(reason_code rc, const disconnect_props& dc_props) {
0067         if constexpr (has_at_disconnect<LoggerType>)
0068             _logger.at_disconnect(rc, dc_props);
0069     }
0070 
0071 };
0072 
0073 } // end namespace boost::mqtt5::detail
0074 
0075 
0076 #endif // !BOOST_MQTT5_LOG_INVOKE_HPP