123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- #ifndef __ASIO2_MQTT_ERROR_HPP__
- #define __ASIO2_MQTT_ERROR_HPP__
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- #pragma once
- #endif
- #include <asio2/base/error.hpp>
- namespace asio2::mqtt
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- enum class error : std::uint8_t
- {
-
- success = 0,
-
- normal_disconnection = 0,
-
- granted_qos_0 = 0,
-
- granted_qos_1 = 1,
-
- granted_qos_2 = 2,
-
- disconnect_with_will_message = 4,
-
- no_matching_subscribers = 16,
-
- no_subscription_existed = 17,
-
- continue_authentication = 24,
-
- reauthenticate = 25,
-
- unspecified_error = 128,
-
- malformed_packet = 129,
-
- protocol_error = 130,
-
- implementation_specific_error = 131,
-
- unsupported_protocol_version = 132,
-
- client_identifier_not_valid = 133,
-
- bad_user_name_or_password = 134,
-
- not_authorized = 135,
-
- server_unavailable = 136,
-
- server_busy = 137,
-
- banned = 138,
-
- server_shutting_down = 139,
-
- bad_authentication_method = 140,
-
- keep_alive_timeout = 141,
-
- session_taken_over = 142,
-
- topic_filter_invalid = 143,
-
- topic_name_invalid = 144,
-
- packet_identifier_in_use = 145,
-
- packet_identifier_not_found = 146,
-
- receive_maximum_exceeded = 147,
-
- topic_alias_invalid = 148,
-
- packet_too_large = 149,
-
- message_rate_too_high = 150,
-
- quota_exceeded = 151,
-
- administrative_action = 152,
-
- payload_format_invalid = 153,
-
- retain_not_supported = 154,
-
- qos_not_supported = 155,
-
- use_another_server = 156,
-
- server_moved = 157,
-
- shared_subscriptions_not_supported = 158,
-
- connection_rate_exceeded = 159,
-
- maximum_connect_time = 160,
-
- subscription_identifiers_not_supported = 161,
-
- wildcard_subscriptions_not_supported = 162,
- };
- enum class condition : std::uint8_t
- {
-
- success = 0,
-
- normal_disconnection = 0,
-
- granted_qos_0 = 0,
-
- granted_qos_1 = 1,
-
- granted_qos_2 = 2,
-
- disconnect_with_will_message = 4,
-
- no_matching_subscribers = 16,
-
- no_subscription_existed = 17,
-
- continue_authentication = 24,
-
- reauthenticate = 25,
-
- unspecified_error = 128,
-
- malformed_packet = 129,
-
- protocol_error = 130,
-
- implementation_specific_error = 131,
-
- unsupported_protocol_version = 132,
-
- client_identifier_not_valid = 133,
-
- bad_user_name_or_password = 134,
-
- not_authorized = 135,
-
- server_unavailable = 136,
-
- server_busy = 137,
-
- banned = 138,
-
- server_shutting_down = 139,
-
- bad_authentication_method = 140,
-
- keep_alive_timeout = 141,
-
- session_taken_over = 142,
-
- topic_filter_invalid = 143,
-
- topic_name_invalid = 144,
-
- packet_identifier_in_use = 145,
-
- packet_identifier_not_found = 146,
-
- receive_maximum_exceeded = 147,
-
- topic_alias_invalid = 148,
-
- packet_too_large = 149,
-
- message_rate_too_high = 150,
-
- quota_exceeded = 151,
-
- administrative_action = 152,
-
- payload_format_invalid = 153,
-
- retain_not_supported = 154,
-
- qos_not_supported = 155,
-
- use_another_server = 156,
-
- server_moved = 157,
-
- shared_subscriptions_not_supported = 158,
-
- connection_rate_exceeded = 159,
-
- maximum_connect_time = 160,
-
- subscription_identifiers_not_supported = 161,
-
- wildcard_subscriptions_not_supported = 162,
- };
-
- using error_category = asio::error_category;
-
- using error_condition = asio::error_condition;
- class mqtt_error_category : public error_category
- {
- public:
- const char* name() const noexcept override
- {
- return "asio2.mqtt";
- }
- inline std::string message(int ev) const override
- {
- switch (static_cast<error>(ev))
- {
- case error::success : return "The operation completed successfully.";
-
-
- case error::granted_qos_1 : return "Granted the PUBLISH Quality of Service is 1";
- case error::granted_qos_2 : return "Granted the PUBLISH Quality of Service is 2";
- case error::disconnect_with_will_message : return "The Client wishes to disconnect but requires that the Server also publishes its Will Message.";
- case error::no_matching_subscribers : return "The message is accepted but there are no subscribers. This is sent only by the Server. If the Server knows that there are no matching subscribers, it MAY use this Reason Code instead of 0x00 (Success).";
- case error::no_subscription_existed : return "No subscription existed";
- case error::continue_authentication : return "Continue the authentication with another step";
- case error::reauthenticate : return "Initiate a re-authentication";
- case error::unspecified_error : return "The Server or Client does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.";
- case error::malformed_packet : return "The received packet does not conform to this specification.";
- case error::protocol_error : return "An unexpected or out of order packet was received.";
- case error::implementation_specific_error : return "The packet received is valid but cannot be processed by this implementation.";
- case error::unsupported_protocol_version : return "The Server does not support the version of the MQTT protocol requested by the Client.";
- case error::client_identifier_not_valid : return "The Client Identifier is a valid string but is not allowed by the Server.";
- case error::bad_user_name_or_password : return "The Server does not accept the User Name or Password specified by the Client";
- case error::not_authorized : return "The request is not authorized.";
- case error::server_unavailable : return "The MQTT Server is not available.";
- case error::server_busy : return "The Server is busy and cannot continue processing requests from this Client.";
- case error::banned : return "This Client has been banned by administrative action. Contact the server administrator.";
- case error::server_shutting_down : return "The Server is shutting down.";
- case error::bad_authentication_method : return "The authentication method is not supported or does not match the authentication method currently in use.";
- case error::keep_alive_timeout : return "The Connection is closed because no packet has been received for 1.5 times the Keepalive time.";
- case error::session_taken_over : return "Another Connection using the same ClientID has connected causing this Connection to be closed.";
- case error::topic_filter_invalid : return "The Topic Filter is correctly formed, but is not accepted by this Sever.";
- case error::topic_name_invalid : return "The Topic Name is not malformed, but is not accepted by this Client or Server.";
- case error::packet_identifier_in_use : return "The Packet Identifier is already in use. This might indicate a mismatch in the Session State between the Client and Server.";
- case error::packet_identifier_not_found : return "The Packet Identifier is not known. This is not an error during recovery, but at other times indicates a mismatch between the Session State on the Client and Server.";
- case error::receive_maximum_exceeded : return "The Client or Server has received more than Receive Maximum publication for which it has not sent PUBACK or PUBCOMP.";
- case error::topic_alias_invalid : return "The Client or Server has received a PUBLISH packet containing a Topic Alias which is greater than the Maximum Topic Alias it sent in the CONNECT or CONNACK packet.";
- case error::packet_too_large : return "The packet size is greater than Maximum Packet Size for this Client or Server.";
- case error::message_rate_too_high : return "The received data rate is too high.";
- case error::quota_exceeded : return "An implementation or administrative imposed limit has been exceeded.";
- case error::administrative_action : return "The Connection is closed due to an administrative action.";
- case error::payload_format_invalid : return "The payload format does not match the specified Payload Format Indicator.";
- case error::retain_not_supported : return "The Server has does not support retained messages.";
- case error::qos_not_supported : return "The Server does not support the QoS set in Will QoS.";
- case error::use_another_server : return "The Client should temporarily use another server.";
- case error::server_moved : return "The Server is moved and the Client should permanently use another server.";
- case error::shared_subscriptions_not_supported : return "The Server does not support Shared Subscriptions.";
- case error::connection_rate_exceeded : return "The connection rate limit has been exceeded.";
- case error::maximum_connect_time : return "The maximum connection time authorized for this connection has been exceeded.";
- case error::subscription_identifiers_not_supported: return "The Server does not support Subscription Identifiers; the subscription is not accepted.";
- case error::wildcard_subscriptions_not_supported : return "The Server does not support Wildcard Subscriptions; the subscription is not accepted.";
- default : return "Unknown error";
- }
- }
- inline error_condition default_error_condition(int ev) const noexcept override
- {
- return error_condition{ ev, *this };
- }
- };
- inline const mqtt_error_category& mqtt_category() noexcept
- {
- static mqtt_error_category const cat{};
- return cat;
- }
- inline asio::error_code make_error_code(error e)
- {
- return asio::error_code{ static_cast<std::underlying_type<error>::type>(e), mqtt_category() };
- }
- inline error_condition make_error_condition(condition c)
- {
- return error_condition{ static_cast<std::underlying_type<condition>::type>(c), mqtt_category() };
- }
- template<typename = void>
- inline constexpr std::string_view to_string(error e)
- {
- using namespace std::string_view_literals;
- switch (e)
- {
- case error::success : return "The operation completed successfully.";
-
-
- case error::granted_qos_1 : return "Granted the PUBLISH Quality of Service is 1";
- case error::granted_qos_2 : return "Granted the PUBLISH Quality of Service is 2";
- case error::disconnect_with_will_message : return "The Client wishes to disconnect but requires that the Server also publishes its Will Message.";
- case error::no_matching_subscribers : return "The message is accepted but there are no subscribers. This is sent only by the Server. If the Server knows that there are no matching subscribers, it MAY use this Reason Code instead of 0x00 (Success).";
- case error::no_subscription_existed : return "No subscription existed";
- case error::continue_authentication : return "Continue the authentication with another step";
- case error::reauthenticate : return "Initiate a re-authentication";
- case error::unspecified_error : return "The Server or Client does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.";
- case error::malformed_packet : return "The received packet does not conform to this specification.";
- case error::protocol_error : return "An unexpected or out of order packet was received.";
- case error::implementation_specific_error : return "The packet received is valid but cannot be processed by this implementation.";
- case error::unsupported_protocol_version : return "The Server does not support the version of the MQTT protocol requested by the Client.";
- case error::client_identifier_not_valid : return "The Client Identifier is a valid string but is not allowed by the Server.";
- case error::bad_user_name_or_password : return "The Server does not accept the User Name or Password specified by the Client";
- case error::not_authorized : return "The request is not authorized.";
- case error::server_unavailable : return "The MQTT Server is not available.";
- case error::server_busy : return "The Server is busy and cannot continue processing requests from this Client.";
- case error::banned : return "This Client has been banned by administrative action. Contact the server administrator.";
- case error::server_shutting_down : return "The Server is shutting down.";
- case error::bad_authentication_method : return "The authentication method is not supported or does not match the authentication method currently in use.";
- case error::keep_alive_timeout : return "The Connection is closed because no packet has been received for 1.5 times the Keepalive time.";
- case error::session_taken_over : return "Another Connection using the same ClientID has connected causing this Connection to be closed.";
- case error::topic_filter_invalid : return "The Topic Filter is correctly formed, but is not accepted by this Sever.";
- case error::topic_name_invalid : return "The Topic Name is not malformed, but is not accepted by this Client or Server.";
- case error::packet_identifier_in_use : return "The Packet Identifier is already in use. This might indicate a mismatch in the Session State between the Client and Server.";
- case error::packet_identifier_not_found : return "The Packet Identifier is not known. This is not an error during recovery, but at other times indicates a mismatch between the Session State on the Client and Server.";
- case error::receive_maximum_exceeded : return "The Client or Server has received more than Receive Maximum publication for which it has not sent PUBACK or PUBCOMP.";
- case error::topic_alias_invalid : return "The Client or Server has received a PUBLISH packet containing a Topic Alias which is greater than the Maximum Topic Alias it sent in the CONNECT or CONNACK packet.";
- case error::packet_too_large : return "The packet size is greater than Maximum Packet Size for this Client or Server.";
- case error::message_rate_too_high : return "The received data rate is too high.";
- case error::quota_exceeded : return "An implementation or administrative imposed limit has been exceeded.";
- case error::administrative_action : return "The Connection is closed due to an administrative action.";
- case error::payload_format_invalid : return "The payload format does not match the specified Payload Format Indicator.";
- case error::retain_not_supported : return "The Server has does not support retained messages.";
- case error::qos_not_supported : return "The Server does not support the QoS set in Will QoS.";
- case error::use_another_server : return "The Client should temporarily use another server.";
- case error::server_moved : return "The Server is moved and the Client should permanently use another server.";
- case error::shared_subscriptions_not_supported : return "The Server does not support Shared Subscriptions.";
- case error::connection_rate_exceeded : return "The connection rate limit has been exceeded.";
- case error::maximum_connect_time : return "The maximum connection time authorized for this connection has been exceeded.";
- case error::subscription_identifiers_not_supported: return "The Server does not support Subscription Identifiers; the subscription is not accepted.";
- case error::wildcard_subscriptions_not_supported : return "The Server does not support Wildcard Subscriptions; the subscription is not accepted.";
- default : return "Unknown error";
- }
- return "Unknown error";
- };
- }
- namespace mqtt = ::asio2::mqtt;
- namespace std
- {
- template<>
- struct is_error_code_enum<::asio2::mqtt::error>
- {
- static bool const value = true;
- };
- template<>
- struct is_error_condition_enum<::asio2::mqtt::condition>
- {
- static bool const value = true;
- };
- }
- #endif
|