Commit 6a66c78c37c3fe616e1eca63823d256e4a061169

Authored by Patric Stout
1 parent 13c76b92

chore: apply some SonarCloud suggestions

src/Client.cpp
... ... @@ -50,9 +50,7 @@ TrueMQTT::Client::Impl::Impl(const std::string_view host,
50 50 {
51 51 }
52 52  
53   -TrueMQTT::Client::Impl::~Impl()
54   -{
55   -}
  53 +TrueMQTT::Client::Impl::~Impl() = default;
56 54  
57 55 void TrueMQTT::Client::setLogger(Client::LogLevel log_level, const std::function<void(Client::LogLevel, std::string_view)> &logger) const
58 56 {
... ... @@ -211,7 +209,7 @@ void TrueMQTT::Client::subscribe(const std::string_view topic, const std::functi
211 209 // Add the callback to the leaf node.
212 210 subscriptions->callbacks.push_back(callback);
213 211  
214   - m_impl->m_subscription_topics.insert(std::string(topic));
  212 + m_impl->m_subscription_topics.emplace(topic);
215 213 if (m_impl->m_state == Client::Impl::State::CONNECTED)
216 214 {
217 215 if (!m_impl->sendSubscribe(topic))
... ...
src/Connection.cpp
... ... @@ -128,7 +128,7 @@ void TrueMQTT::Client::Impl::Connection::runRead()
128 128  
129 129 std::optional<Packet> TrueMQTT::Client::Impl::Connection::popSendQueueBlocking()
130 130 {
131   - std::unique_lock<std::mutex> lock(m_send_queue_mutex);
  131 + std::unique_lock lock(m_send_queue_mutex);
132 132 if (!m_send_queue.empty())
133 133 {
134 134 auto packet = m_send_queue.front();
... ... @@ -213,7 +213,7 @@ void TrueMQTT::Client::Impl::Connection::resolve()
213 213 int error = getaddrinfo(m_impl.m_host.c_str(), std::to_string(m_impl.m_port).c_str(), &hints, &m_host_resolved);
214 214 if (error != 0)
215 215 {
216   - m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string(gai_strerror(error)));
  216 + m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string_view(gai_strerror(error)));
217 217 return;
218 218 }
219 219  
... ...
src/Connection.h
... ... @@ -29,7 +29,7 @@
29 29 class TrueMQTT::Client::Impl::Connection
30 30 {
31 31 public:
32   - Connection(TrueMQTT::Client::Impl &impl);
  32 + explicit Connection(TrueMQTT::Client::Impl &impl);
33 33 ~Connection();
34 34  
35 35 bool send(Packet packet, bool has_priority = false);
... ...
src/Packet.h
... ... @@ -13,7 +13,7 @@
13 13 class Packet
14 14 {
15 15 public:
16   - enum class PacketType
  16 + enum class PacketType : uint8_t
17 17 {
18 18 CONNECT = 1,
19 19 CONNACK = 2,
... ...