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_INTERNAL_TYPES_HPP
0009 #define BOOST_MQTT5_INTERNAL_TYPES_HPP
0010 
0011 #include <boost/mqtt5/error.hpp>
0012 #include <boost/mqtt5/types.hpp>
0013 
0014 #include <boost/mqtt5/detail/any_authenticator.hpp>
0015 
0016 #include <chrono>
0017 #include <cstdint>
0018 #include <optional>
0019 #include <string>
0020 
0021 namespace boost::mqtt5::detail {
0022 
0023 using byte_citer = std::string::const_iterator;
0024 
0025 using time_stamp = std::chrono::time_point<std::chrono::steady_clock>;
0026 using duration = time_stamp::duration;
0027 
0028 struct credentials {
0029     std::string client_id;
0030     std::optional<std::string> username;
0031     std::optional<std::string> password;
0032 
0033     credentials() = default;
0034     credentials(
0035         std::string client_id,
0036         std::string username, std::string password
0037     ) :
0038         client_id(std::move(client_id))
0039     {
0040         if (!username.empty())
0041             this->username = std::move(username);
0042         if (!password.empty())
0043             this->password = std::move(password);
0044     }
0045 };
0046 
0047 class session_state {
0048     uint8_t _flags = 0b00;
0049 
0050     static constexpr uint8_t session_present_flag = 0b01;
0051     static constexpr uint8_t subscriptions_present_flag = 0b10;
0052 public:
0053     void session_present(bool present) {
0054         return update_flag(present, session_present_flag);
0055     }
0056 
0057     bool session_present() const {
0058         return _flags & session_present_flag;
0059     }
0060 
0061     void subscriptions_present(bool present) {
0062         return update_flag(present, subscriptions_present_flag);
0063     }
0064 
0065     bool subscriptions_present() const {
0066         return _flags & subscriptions_present_flag;
0067     }
0068 
0069 private:
0070     void update_flag(bool set, uint8_t flag) {
0071         if (set)
0072             _flags |= flag;
0073         else
0074             _flags &= ~flag;
0075     }
0076 };
0077 
0078 struct mqtt_ctx {
0079     credentials creds;
0080     std::optional<will> will_msg;
0081     uint16_t keep_alive = 60;
0082     connect_props co_props;
0083     connack_props ca_props;
0084     session_state state;
0085     any_authenticator authenticator;
0086 
0087     mqtt_ctx() = default;
0088 
0089     mqtt_ctx(const mqtt_ctx& other) :
0090         creds(other.creds), will_msg(other.will_msg),
0091         keep_alive(other.keep_alive), co_props(other.co_props),
0092         ca_props {}, state {},
0093         authenticator(other.authenticator)
0094     {}
0095 };
0096 
0097 struct disconnect_ctx {
0098     disconnect_rc_e reason_code = disconnect_rc_e::normal_disconnection;
0099     disconnect_props props = {};
0100     bool terminal = false;
0101 };
0102 
0103 using serial_num_t = uint32_t;
0104 constexpr serial_num_t no_serial = 0;
0105 
0106 namespace send_flag {
0107 
0108 constexpr unsigned none = 0b000;
0109 constexpr unsigned throttled = 0b001;
0110 constexpr unsigned prioritized = 0b010;
0111 constexpr unsigned terminal = 0b100;
0112 
0113 };
0114 
0115 } // end namespace boost::mqtt5::detail
0116 
0117 #endif // !BOOST_MQTT5_INTERNAL_TYPES_HPP