diff --git a/include/async_mqtt5/impl/client_service.hpp b/include/async_mqtt5/impl/client_service.hpp index a35e42a..f03f3bb 100644 --- a/include/async_mqtt5/impl/client_service.hpp +++ b/include/async_mqtt5/impl/client_service.hpp @@ -71,26 +71,32 @@ public: _mqtt_context.will_msg = std::move(will); } - template - const auto& connack_property(Prop p) const { - return _mqtt_context.ca_props[p]; + template + const auto& connack_property( + std::integral_constant prop + ) const { + return _mqtt_context.ca_props[prop]; } const auto& connack_properties() const { return _mqtt_context.ca_props; } - template - const auto& connect_property(Prop p) const { - return _mqtt_context.co_props[p]; + template + const auto& connect_property( + std::integral_constant prop + ) const { + return _mqtt_context.co_props[prop]; } - template - auto& connect_property(Prop p) { - return _mqtt_context.co_props[p]; + template + auto& connect_property( + std::integral_constant prop + ) { + return _mqtt_context.co_props[prop]; } - void connect_propertiess(connect_props props) { + void connect_properties(connect_props props) { _mqtt_context.co_props = std::move(props); } @@ -144,23 +150,29 @@ public: _mqtt_context.will_msg = std::move(will); } - template - const auto& connack_property(Prop p) const { - return _mqtt_context.ca_props[p]; + template + const auto& connack_property( + std::integral_constant prop + ) const { + return _mqtt_context.ca_props[prop]; } const auto& connack_properties() const { return _mqtt_context.ca_props; } - template - const auto& connect_property(Prop p) const { - return _mqtt_context.co_props[p]; + template + const auto& connect_property( + std::integral_constant prop + ) const { + return _mqtt_context.co_props[prop]; } - template - auto& connect_property(Prop p) { - return _mqtt_context.co_props[p]; + template + auto& connect_property( + std::integral_constant prop + ) { + return _mqtt_context.co_props[prop]; } void connect_properties(connect_props props) { @@ -323,14 +335,20 @@ public: _stream_context.mqtt_context().keep_alive = seconds; } - template - const auto& connect_property(Prop p) const { - return _stream_context.connect_property(p); + template + const auto& connect_property( + std::integral_constant prop + ) const { + return _stream_context.connect_property(prop); } - template - auto& connect_property(Prop p) { - return _stream_context.connect_property(p); + template + void connect_property( + std::integral_constant prop, + prop::value_type_t

value + ){ + if (!is_open()) + _stream_context.connect_property(prop) = value; } void connect_properties(connect_props props) { @@ -338,9 +356,11 @@ public: _stream_context.connect_properties(std::move(props)); } - template - const auto& connack_property(Prop p) const { - return _stream_context.connack_property(p); + template + const auto& connack_property( + std::integral_constant prop + ) const { + return _stream_context.connack_property(prop); } const auto& connack_properties() const { diff --git a/include/async_mqtt5/mqtt_client.hpp b/include/async_mqtt5/mqtt_client.hpp index 3ec6aea..a9a98ef 100644 --- a/include/async_mqtt5/mqtt_client.hpp +++ b/include/async_mqtt5/mqtt_client.hpp @@ -349,7 +349,7 @@ public: std::integral_constant prop, prop::value_type_t

value ) { - _impl->connect_property(prop) = value; + _svc_ptr->connect_property(prop, std::move(value)); return *this; } diff --git a/include/async_mqtt5/types.hpp b/include/async_mqtt5/types.hpp index f084536..eec6786 100644 --- a/include/async_mqtt5/types.hpp +++ b/include/async_mqtt5/types.hpp @@ -282,6 +282,10 @@ class will : public will_props { public: /** * \brief Constructs an empty Will Message. + * + * \attention Do not use! + * An empty Will Message results in an empty Topic Name which is not valid. + * Internal uses only. */ will() = default;