From 584030bec45c446202007c0af35ca8a081494c01 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 17 Sep 2022 11:04:54 +0200 Subject: [PATCH] chore(coding-style): remove this-> and prefix member variables with m_ --- src/Client.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------ src/ClientImpl.h | 44 ++++++++++++++++++++++---------------------- src/Connection.cpp | 42 +++++++++++++++++++++--------------------- src/Log.h | 70 +++++++++++++++++++++++++++++++++++----------------------------------- src/Packet.cpp | 20 ++++++++++---------- 5 files changed, 166 insertions(+), 166 deletions(-) diff --git a/src/Client.cpp b/src/Client.cpp index b208f91..8b04362 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -21,16 +21,16 @@ TrueMQTT::Client::Client(const std::string &host, std::chrono::milliseconds connection_backoff_max, std::chrono::milliseconds keep_alive_interval) { - this->m_impl = std::make_unique(host, port, client_id, connection_timeout, connection_backoff, connection_backoff_max, keep_alive_interval); + m_impl = std::make_unique(host, port, client_id, connection_timeout, connection_backoff, connection_backoff_max, keep_alive_interval); - LOG_TRACE(this->m_impl, "Constructor of client called"); + LOG_TRACE(m_impl, "Constructor of client called"); } TrueMQTT::Client::~Client() { - LOG_TRACE(this->m_impl, "Destructor of client called"); + LOG_TRACE(m_impl, "Destructor of client called"); - this->disconnect(); + disconnect(); } TrueMQTT::Client::Impl::Impl(const std::string &host, @@ -40,13 +40,13 @@ TrueMQTT::Client::Impl::Impl(const std::string &host, std::chrono::milliseconds connection_backoff, std::chrono::milliseconds connection_backoff_max, std::chrono::milliseconds keep_alive_interval) - : host(host), - port(port), - client_id(client_id), - connection_timeout(connection_timeout), - connection_backoff(connection_backoff), - connection_backoff_max(connection_backoff_max), - keep_alive_interval(keep_alive_interval) + : m_host(host), + m_port(port), + m_client_id(client_id), + m_connection_timeout(connection_timeout), + m_connection_backoff(connection_backoff), + m_connection_backoff_max(connection_backoff_max), + m_keep_alive_interval(keep_alive_interval) { } @@ -56,112 +56,112 @@ TrueMQTT::Client::Impl::~Impl() void TrueMQTT::Client::setLogger(Client::LogLevel log_level, const std::function &logger) const { - LOG_TRACE(this->m_impl, "Setting logger to log level " + std::to_string(log_level)); + LOG_TRACE(m_impl, "Setting logger to log level " + std::to_string(log_level)); - this->m_impl->log_level = log_level; - this->m_impl->logger = logger; + m_impl->m_log_level = log_level; + m_impl->m_logger = logger; - LOG_DEBUG(this->m_impl, "Log level now on " + std::to_string(this->m_impl->log_level)); + LOG_DEBUG(m_impl, "Log level now on " + std::to_string(m_impl->m_log_level)); } void TrueMQTT::Client::setLastWill(const std::string &topic, const std::string &payload, bool retain) const { - if (this->m_impl->state != Client::Impl::State::DISCONNECTED) + if (m_impl->m_state != Client::Impl::State::DISCONNECTED) { - LOG_ERROR(this->m_impl, "Cannot set last will when not disconnected"); + LOG_ERROR(m_impl, "Cannot set last will when not disconnected"); return; } - LOG_TRACE(this->m_impl, "Setting last will to topic " + topic + " with payload " + payload + " and retain " + std::to_string(retain)); + LOG_TRACE(m_impl, "Setting last will to topic " + topic + " with payload " + payload + " and retain " + std::to_string(retain)); - this->m_impl->last_will_topic = topic; - this->m_impl->last_will_payload = payload; - this->m_impl->last_will_retain = retain; + m_impl->m_last_will_topic = topic; + m_impl->m_last_will_payload = payload; + m_impl->m_last_will_retain = retain; } void TrueMQTT::Client::setErrorCallback(const std::function &callback) const { - LOG_TRACE(this->m_impl, "Setting error callback"); + LOG_TRACE(m_impl, "Setting error callback"); - this->m_impl->error_callback = callback; + m_impl->m_error_callback = callback; } void TrueMQTT::Client::setPublishQueue(Client::PublishQueueType queue_type, size_t size) const { - if (this->m_impl->state != Client::Impl::State::DISCONNECTED) + if (m_impl->m_state != Client::Impl::State::DISCONNECTED) { - LOG_ERROR(this->m_impl, "Cannot set publish queue when not disconnected"); + LOG_ERROR(m_impl, "Cannot set publish queue when not disconnected"); return; } - LOG_TRACE(this->m_impl, "Setting publish queue to type " + std::to_string(queue_type) + " and size " + std::to_string(size)); + LOG_TRACE(m_impl, "Setting publish queue to type " + std::to_string(queue_type) + " and size " + std::to_string(size)); - this->m_impl->publish_queue_type = queue_type; - this->m_impl->publish_queue_size = size; + m_impl->m_publish_queue_type = queue_type; + m_impl->m_publish_queue_size = size; } void TrueMQTT::Client::connect() const { - std::scoped_lock lock(this->m_impl->state_mutex); + std::scoped_lock lock(m_impl->m_state_mutex); - if (this->m_impl->state != Client::Impl::State::DISCONNECTED) + if (m_impl->m_state != Client::Impl::State::DISCONNECTED) { return; } - LOG_INFO(this->m_impl, "Connecting to " + this->m_impl->host + ":" + std::to_string(this->m_impl->port)); + LOG_INFO(m_impl, "Connecting to " + m_impl->m_host + ":" + std::to_string(m_impl->m_port)); - this->m_impl->state = Client::Impl::State::CONNECTING; - this->m_impl->connect(); + m_impl->m_state = Client::Impl::State::CONNECTING; + m_impl->connect(); } void TrueMQTT::Client::disconnect() const { - std::scoped_lock lock(this->m_impl->state_mutex); + std::scoped_lock lock(m_impl->m_state_mutex); - if (this->m_impl->state == Client::Impl::State::DISCONNECTED) + if (m_impl->m_state == Client::Impl::State::DISCONNECTED) { - LOG_TRACE(this->m_impl, "Already disconnected"); + LOG_TRACE(m_impl, "Already disconnected"); return; } - LOG_INFO(this->m_impl, "Disconnecting from broker"); + LOG_INFO(m_impl, "Disconnecting from broker"); - this->m_impl->state = Client::Impl::State::DISCONNECTED; - this->m_impl->disconnect(); + m_impl->m_state = Client::Impl::State::DISCONNECTED; + m_impl->disconnect(); } void TrueMQTT::Client::publish(const std::string &topic, const std::string &payload, bool retain) const { - std::scoped_lock lock(this->m_impl->state_mutex); + std::scoped_lock lock(m_impl->m_state_mutex); - LOG_DEBUG(this->m_impl, "Publishing message on topic '" + topic + "': " + payload + " (" + (retain ? "retained" : "not retained") + ")"); + LOG_DEBUG(m_impl, "Publishing message on topic '" + topic + "': " + payload + " (" + (retain ? "retained" : "not retained") + ")"); - switch (this->m_impl->state) + switch (m_impl->m_state) { case Client::Impl::State::DISCONNECTED: - LOG_ERROR(this->m_impl, "Cannot publish when disconnected"); + LOG_ERROR(m_impl, "Cannot publish when disconnected"); return; case Client::Impl::State::CONNECTING: - this->m_impl->toPublishQueue(topic, payload, retain); + m_impl->toPublishQueue(topic, payload, retain); return; case Client::Impl::State::CONNECTED: - this->m_impl->sendPublish(topic, payload, retain); + m_impl->sendPublish(topic, payload, retain); return; } } void TrueMQTT::Client::subscribe(const std::string &topic, const std::function &callback) const { - std::scoped_lock lock(this->m_impl->state_mutex); + std::scoped_lock lock(m_impl->m_state_mutex); - if (this->m_impl->state == Client::Impl::State::DISCONNECTED) + if (m_impl->m_state == Client::Impl::State::DISCONNECTED) { - LOG_ERROR(this->m_impl, "Cannot subscribe when disconnected"); + LOG_ERROR(m_impl, "Cannot subscribe when disconnected"); return; } - LOG_DEBUG(this->m_impl, "Subscribing to topic '" + topic + "'"); + LOG_DEBUG(m_impl, "Subscribing to topic '" + topic + "'"); // Split the topic on /, to find each part. std::string part; @@ -169,7 +169,7 @@ void TrueMQTT::Client::subscribe(const std::string &topic, const std::functionm_impl->subscriptions.try_emplace(part).first->second; + Client::Impl::SubscriptionPart *subscriptions = &m_impl->m_subscriptions.try_emplace(part).first->second; while (std::getline(stopic, part, '/')) { subscriptions = &subscriptions->children.try_emplace(part).first->second; @@ -177,24 +177,24 @@ void TrueMQTT::Client::subscribe(const std::string &topic, const std::functioncallbacks.push_back(callback); - this->m_impl->subscription_topics.insert(topic); - if (this->m_impl->state == Client::Impl::State::CONNECTED) + m_impl->m_subscription_topics.insert(topic); + if (m_impl->m_state == Client::Impl::State::CONNECTED) { - this->m_impl->sendSubscribe(topic); + m_impl->sendSubscribe(topic); } } void TrueMQTT::Client::unsubscribe(const std::string &topic) const { - std::scoped_lock lock(this->m_impl->state_mutex); + std::scoped_lock lock(m_impl->m_state_mutex); - if (this->m_impl->state == Client::Impl::State::DISCONNECTED) + if (m_impl->m_state == Client::Impl::State::DISCONNECTED) { - LOG_ERROR(this->m_impl, "Cannot unsubscribe when disconnected"); + LOG_ERROR(m_impl, "Cannot unsubscribe when disconnected"); return; } - LOG_DEBUG(this->m_impl, "Unsubscribing from topic '" + topic + "'"); + LOG_DEBUG(m_impl, "Unsubscribing from topic '" + topic + "'"); // Split the topic on /, to find each part. std::string part; @@ -203,7 +203,7 @@ void TrueMQTT::Client::unsubscribe(const std::string &topic) const // Find the root node, and walk down till we find the leaf node. std::vector> reverse; - Client::Impl::SubscriptionPart *subscriptions = &this->m_impl->subscriptions[part]; + Client::Impl::SubscriptionPart *subscriptions = &m_impl->m_subscriptions[part]; reverse.emplace_back(part, subscriptions); while (std::getline(stopic, part, '/')) { @@ -232,25 +232,25 @@ void TrueMQTT::Client::unsubscribe(const std::string &topic) const } if (!remove_next.empty()) { - this->m_impl->subscriptions.erase(remove_next); + m_impl->m_subscriptions.erase(remove_next); } - this->m_impl->subscription_topics.erase(topic); - if (this->m_impl->state == Client::Impl::State::CONNECTED) + m_impl->m_subscription_topics.erase(topic); + if (m_impl->m_state == Client::Impl::State::CONNECTED) { - this->m_impl->sendUnsubscribe(topic); + m_impl->sendUnsubscribe(topic); } } void TrueMQTT::Client::Impl::connectionStateChange(bool connected) { - std::scoped_lock lock(this->state_mutex); + std::scoped_lock lock(m_state_mutex); if (connected) { LOG_INFO(this, "Connected to broker"); - this->state = Client::Impl::State::CONNECTED; + m_state = Client::Impl::State::CONNECTED; // Restoring subscriptions and flushing the queue is done while still under // the lock. This to prevent \ref disconnect from being called while we are @@ -261,55 +261,55 @@ void TrueMQTT::Client::Impl::connectionStateChange(bool connected) // implementation. // First restore any subscription. - for (auto &subscription : this->subscription_topics) + for (auto &subscription : m_subscription_topics) { - this->sendSubscribe(subscription); + sendSubscribe(subscription); } // Flush the publish queue. - for (const auto &[topic, payload, retain] : this->publish_queue) + for (const auto &[topic, payload, retain] : m_publish_queue) { - this->sendPublish(topic, payload, retain); + sendPublish(topic, payload, retain); } - this->publish_queue.clear(); + m_publish_queue.clear(); } else { LOG_INFO(this, "Disconnected from broker"); - this->state = Client::Impl::State::CONNECTING; + m_state = Client::Impl::State::CONNECTING; } } void TrueMQTT::Client::Impl::toPublishQueue(const std::string &topic, const std::string &payload, bool retain) { - if (this->state != Client::Impl::State::CONNECTING) + if (m_state != Client::Impl::State::CONNECTING) { LOG_ERROR(this, "Cannot queue publish message when not connecting"); return; } - switch (this->publish_queue_type) + switch (m_publish_queue_type) { case Client::PublishQueueType::DROP: LOG_WARNING(this, "Publish queue is disabled, dropping message"); return; case Client::PublishQueueType::FIFO: - if (this->publish_queue.size() >= this->publish_queue_size) + if (m_publish_queue.size() >= m_publish_queue_size) { LOG_WARNING(this, "Publish queue is full, dropping oldest message on queue"); - this->publish_queue.pop_front(); + m_publish_queue.pop_front(); } break; case Client::PublishQueueType::LIFO: - if (this->publish_queue.size() >= this->publish_queue_size) + if (m_publish_queue.size() >= m_publish_queue_size) { LOG_WARNING(this, "Publish queue is full, dropping newest message on queue"); - this->publish_queue.pop_back(); + m_publish_queue.pop_back(); } break; } LOG_TRACE(this, "Adding message to publish queue"); - this->publish_queue.emplace_back(topic, payload, retain); + m_publish_queue.emplace_back(topic, payload, retain); } void TrueMQTT::Client::Impl::findSubscriptionMatch(std::vector> &matching_callbacks, const std::map &subscriptions, std::deque &parts) @@ -372,7 +372,7 @@ void TrueMQTT::Client::Impl::messageReceived(std::string topic, std::string payl // Find the matching subscription(s) with recursion. std::vector> matching_callbacks; - findSubscriptionMatch(matching_callbacks, subscriptions, parts); + findSubscriptionMatch(matching_callbacks, m_subscriptions, parts); LOG_TRACE(this, "Found " + std::to_string(matching_callbacks.size()) + " subscription(s) for topic '" + topic + "'"); diff --git a/src/ClientImpl.h b/src/ClientImpl.h index f468f4e..790e52f 100644 --- a/src/ClientImpl.h +++ b/src/ClientImpl.h @@ -56,34 +56,34 @@ public: void findSubscriptionMatch(std::vector> &callbacks, const std::map &subscriptions, std::deque &parts); ///< Recursive function to find any matching subscription based on parts. - State state = State::DISCONNECTED; ///< The current state of the client. - std::mutex state_mutex; ///< Mutex to protect state changes. + State m_state = State::DISCONNECTED; ///< The current state of the client. + std::mutex m_state_mutex; ///< Mutex to protect state changes. - std::string host; ///< Host of the broker. - int port; ///< Port of the broker. - std::string client_id; ///< Client ID to use when connecting to the broker. - std::chrono::milliseconds connection_timeout; ///< Timeout in seconds for the connection to the broker. - std::chrono::milliseconds connection_backoff; ///< Backoff time when connection to the broker failed. This is doubled every time a connection fails, up till \ref connection_backoff_max. - std::chrono::milliseconds connection_backoff_max; ///< Maximum time between backoff attempts in seconds. - std::chrono::milliseconds keep_alive_interval; ///< Interval in seconds between keep-alive messages. + std::string m_host; ///< Host of the broker. + int m_port; ///< Port of the broker. + std::string m_client_id; ///< Client ID to use when connecting to the broker. + std::chrono::milliseconds m_connection_timeout; ///< Timeout in seconds for the connection to the broker. + std::chrono::milliseconds m_connection_backoff; ///< Backoff time when connection to the broker failed. This is doubled every time a connection fails, up till \ref connection_backoff_max. + std::chrono::milliseconds m_connection_backoff_max; ///< Maximum time between backoff attempts in seconds. + std::chrono::milliseconds m_keep_alive_interval; ///< Interval in seconds between keep-alive messages. - Client::LogLevel log_level = Client::LogLevel::NONE; ///< The log level to use. - std::function logger = [](Client::LogLevel, std::string) { /* empty */ }; ///< Logger callback. + Client::LogLevel m_log_level = Client::LogLevel::NONE; ///< The log level to use. + std::function m_logger = [](Client::LogLevel, std::string) { /* empty */ }; ///< Logger callback. - std::string last_will_topic = ""; ///< Topic to publish the last will message to. - std::string last_will_payload = ""; ///< Payload of the last will message. - bool last_will_retain = false; ///< Whether to retain the last will message. + std::string m_last_will_topic = ""; ///< Topic to publish the last will message to. + std::string m_last_will_payload = ""; ///< Payload of the last will message. + bool m_last_will_retain = false; ///< Whether to retain the last will message. - std::function error_callback = [](Error, std::string) { /* empty */ }; ///< Error callback. + std::function m_error_callback = [](Error, std::string) { /* empty */ }; ///< Error callback. - Client::PublishQueueType publish_queue_type = Client::PublishQueueType::DROP; ///< The type of queue to use for the publish queue. - size_t publish_queue_size = -1; ///< Size of the publish queue. - std::deque> publish_queue; ///< Queue of publish messages to send to the broker. + Client::PublishQueueType m_publish_queue_type = Client::PublishQueueType::DROP; ///< The type of queue to use for the publish queue. + size_t m_publish_queue_size = -1; ///< Size of the publish queue. + std::deque> m_publish_queue; ///< Queue of publish messages to send to the broker. - std::set subscription_topics; ///< Flat list of topics the client is subscribed to. - std::map subscriptions; ///< Tree of active subscriptions build up from the parts on the topic. + std::set m_subscription_topics; ///< Flat list of topics the client is subscribed to. + std::map m_subscriptions; ///< Tree of active subscriptions build up from the parts on the topic. class Connection; - std::unique_ptr connection; ///< Connection to the broker. - uint16_t packet_id = 0; ///< The next packet ID to use. Will overflow on 65535 to 0. + std::unique_ptr m_connection; ///< Connection to the broker. + uint16_t m_packet_id = 0; ///< The next packet ID to use. Will overflow on 65535 to 0. }; diff --git a/src/Connection.cpp b/src/Connection.cpp index ce1be83..78ce045 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -19,7 +19,7 @@ TrueMQTT::Client::Impl::Connection::Connection(Client::Impl &impl) : m_impl(impl), m_thread(&Connection::run, this), - m_backoff(impl.connection_backoff) + m_backoff(impl.m_connection_backoff) { } @@ -35,10 +35,10 @@ TrueMQTT::Client::Impl::Connection::~Connection() // freeaddrinfo() is one of those functions that doesn't take kind to NULL pointers // on some platforms. - if (this->m_host_resolved != nullptr) + if (m_host_resolved != nullptr) { - freeaddrinfo(this->m_host_resolved); - this->m_host_resolved = nullptr; + freeaddrinfo(m_host_resolved); + m_host_resolved = nullptr; } } @@ -74,9 +74,9 @@ void TrueMQTT::Client::Impl::Connection::run() // Calculate the next backoff time, slowly reducing how often we retry. m_backoff *= 2; - if (m_backoff > m_impl.connection_backoff_max) + if (m_backoff > m_impl.m_connection_backoff_max) { - m_backoff = m_impl.connection_backoff_max; + m_backoff = m_impl.m_connection_backoff_max; } m_state = State::RESOLVING; @@ -126,19 +126,19 @@ void TrueMQTT::Client::Impl::Connection::resolve() hints.ai_flags = AI_ADDRCONFIG; // If we resolved previously, free the result. - if (this->m_host_resolved != nullptr) + if (m_host_resolved != nullptr) { - freeaddrinfo(this->m_host_resolved); - this->m_host_resolved = nullptr; + freeaddrinfo(m_host_resolved); + m_host_resolved = nullptr; } // Request the OS to resolve the hostname into an IP address. // We do this even if the hostname is already an IP address, as that // makes for far easier code. - int error = getaddrinfo(m_impl.host.c_str(), std::to_string(m_impl.port).c_str(), &hints, &m_host_resolved); + int error = getaddrinfo(m_impl.m_host.c_str(), std::to_string(m_impl.m_port).c_str(), &hints, &m_host_resolved); if (error != 0) { - m_impl.error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string(gai_strerror(error))); + m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string(gai_strerror(error))); return; } @@ -146,7 +146,7 @@ void TrueMQTT::Client::Impl::Connection::resolve() // IPv6. std::deque addresses_ipv4; std::deque addresses_ipv6; - for (addrinfo *ai = this->m_host_resolved; ai != nullptr; ai = ai->ai_next) + for (addrinfo *ai = m_host_resolved; ai != nullptr; ai = ai->ai_next) { if (ai->ai_family == AF_INET6) { @@ -181,9 +181,9 @@ void TrueMQTT::Client::Impl::Connection::resolve() #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_DEBUG // For debugging, print the addresses we resolved into. - if (m_impl.log_level >= TrueMQTT::Client::LogLevel::DEBUG) + if (m_impl.m_log_level >= TrueMQTT::Client::LogLevel::DEBUG) { - LOG_DEBUG(&m_impl, "Resolved hostname '" + m_impl.host + "' to:"); + LOG_DEBUG(&m_impl, "Resolved hostname '" + m_impl.m_host + "' to:"); for (const addrinfo *res : m_addresses) { LOG_DEBUG(&m_impl, "- " + addrinfoToString(res)); @@ -194,7 +194,7 @@ void TrueMQTT::Client::Impl::Connection::resolve() // In some odd cases, the list can be empty. This is a fatal error. if (m_addresses.empty()) { - m_impl.error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, ""); + m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, ""); return; } @@ -255,7 +255,7 @@ bool TrueMQTT::Client::Impl::Connection::connectToAny() } // Check if it is more than the timeout ago since we last tried a connection. - if (std::chrono::steady_clock::now() < m_last_attempt + m_impl.connection_timeout) + if (std::chrono::steady_clock::now() < m_last_attempt + m_impl.m_connection_timeout) { return true; } @@ -328,7 +328,7 @@ bool TrueMQTT::Client::Impl::Connection::connectToAny() LOG_WARNING(&m_impl, "Could not set socket to non-blocking; expect performance impact"); } - m_backoff = m_impl.connection_backoff; + m_backoff = m_impl.m_connection_backoff; m_socket = socket_connected; // Only change the state if no disconnect() has been requested in the mean time. @@ -398,13 +398,13 @@ void TrueMQTT::Client::Impl::Connection::connect(addrinfo *address) void TrueMQTT::Client::Impl::connect() { - this->connection = std::make_unique(*this); + m_connection = std::make_unique(*this); } void TrueMQTT::Client::Impl::disconnect() { - this->subscriptions.clear(); - this->publish_queue.clear(); + m_subscriptions.clear(); + m_publish_queue.clear(); - this->connection.reset(); + m_connection.reset(); } diff --git a/src/Log.h b/src/Log.h index 4e12ec1..f7d46ad 100644 --- a/src/Log.h +++ b/src/Log.h @@ -22,65 +22,65 @@ #endif #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_ERROR -#define LOG_ERROR(obj, x) \ - do \ - { \ - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::ERROR) \ - { \ - (obj)->logger(TrueMQTT::Client::LogLevel::ERROR, x); \ - } \ +#define LOG_ERROR(obj, x) \ + do \ + { \ + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::ERROR) \ + { \ + (obj)->m_logger(TrueMQTT::Client::LogLevel::ERROR, x); \ + } \ } while (0) #else #define LOG_ERROR(obj, x) #endif #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_WARNING -#define LOG_WARNING(obj, x) \ - do \ - { \ - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::WARNING) \ - { \ - (obj)->logger(TrueMQTT::Client::LogLevel::WARNING, x); \ - } \ +#define LOG_WARNING(obj, x) \ + do \ + { \ + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::WARNING) \ + { \ + (obj)->m_logger(TrueMQTT::Client::LogLevel::WARNING, x); \ + } \ } while (0) #else #define LOG_WARNING(obj, x) #endif #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_INFO -#define LOG_INFO(obj, x) \ - do \ - { \ - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::INFO) \ - { \ - (obj)->logger(TrueMQTT::Client::LogLevel::INFO, x); \ - } \ +#define LOG_INFO(obj, x) \ + do \ + { \ + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::INFO) \ + { \ + (obj)->m_logger(TrueMQTT::Client::LogLevel::INFO, x); \ + } \ } while (0) #else #define LOG_INFO(obj, x) #endif #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_DEBUG -#define LOG_DEBUG(obj, x) \ - do \ - { \ - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::DEBUG) \ - { \ - (obj)->logger(TrueMQTT::Client::LogLevel::DEBUG, x); \ - } \ +#define LOG_DEBUG(obj, x) \ + do \ + { \ + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::DEBUG) \ + { \ + (obj)->m_logger(TrueMQTT::Client::LogLevel::DEBUG, x); \ + } \ } while (0) #else #define LOG_DEBUG(obj, x) #endif #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_TRACE -#define LOG_TRACE(obj, x) \ - do \ - { \ - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::TRACE) \ - { \ - (obj)->logger(TrueMQTT::Client::LogLevel::TRACE, x); \ - } \ +#define LOG_TRACE(obj, x) \ + do \ + { \ + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::TRACE) \ + { \ + (obj)->m_logger(TrueMQTT::Client::LogLevel::TRACE, x); \ + } \ } while (0) #else #define LOG_TRACE(obj, x) diff --git a/src/Packet.cpp b/src/Packet.cpp index 44b98aa..0348d26 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -295,7 +295,7 @@ bool TrueMQTT::Client::Impl::Connection::recvLoop() { LOG_WARNING(&m_impl, "Broker refused our subscription"); // TODO -- Keep track of the topic per ticket - m_impl.error_callback(TrueMQTT::Client::Error::SUBSCRIBE_FAILED, ""); + m_impl.m_error_callback(TrueMQTT::Client::Error::SUBSCRIBE_FAILED, ""); } break; @@ -396,7 +396,7 @@ void TrueMQTT::Client::Impl::sendPublish(const std::string &topic, const std::st packet.write_string(topic); packet.write(payload.c_str(), payload.size()); - connection->send(packet); + m_connection->send(packet); } void TrueMQTT::Client::Impl::sendSubscribe(const std::string &topic) @@ -406,16 +406,16 @@ void TrueMQTT::Client::Impl::sendSubscribe(const std::string &topic) Packet packet(Packet::PacketType::SUBSCRIBE, 2); // By specs, packet-id zero is not allowed. - if (packet_id == 0) + if (m_packet_id == 0) { - packet_id++; + m_packet_id++; } - packet.write_uint16(packet_id++); + packet.write_uint16(m_packet_id++); packet.write_string(topic); packet.write_uint8(0); // QoS - connection->send(packet); + m_connection->send(packet); } void TrueMQTT::Client::Impl::sendUnsubscribe(const std::string &topic) @@ -425,13 +425,13 @@ void TrueMQTT::Client::Impl::sendUnsubscribe(const std::string &topic) Packet packet(Packet::PacketType::UNSUBSCRIBE, 2); // By specs, packet-id zero is not allowed. - if (packet_id == 0) + if (m_packet_id == 0) { - packet_id++; + m_packet_id++; } - packet.write_uint16(packet_id++); + packet.write_uint16(m_packet_id++); packet.write_string(topic); - connection->send(packet); + m_connection->send(packet); } -- libgit2 0.21.4