Commit 584030bec45c446202007c0af35ca8a081494c01

Authored by Patric Stout
1 parent 81f19eca

chore(coding-style): remove this-> and prefix member variables with m_

src/Client.cpp
... ... @@ -21,16 +21,16 @@ TrueMQTT::Client::Client(const std::string &host,
21 21 std::chrono::milliseconds connection_backoff_max,
22 22 std::chrono::milliseconds keep_alive_interval)
23 23 {
24   - this->m_impl = std::make_unique<Client::Impl>(host, port, client_id, connection_timeout, connection_backoff, connection_backoff_max, keep_alive_interval);
  24 + m_impl = std::make_unique<Client::Impl>(host, port, client_id, connection_timeout, connection_backoff, connection_backoff_max, keep_alive_interval);
25 25  
26   - LOG_TRACE(this->m_impl, "Constructor of client called");
  26 + LOG_TRACE(m_impl, "Constructor of client called");
27 27 }
28 28  
29 29 TrueMQTT::Client::~Client()
30 30 {
31   - LOG_TRACE(this->m_impl, "Destructor of client called");
  31 + LOG_TRACE(m_impl, "Destructor of client called");
32 32  
33   - this->disconnect();
  33 + disconnect();
34 34 }
35 35  
36 36 TrueMQTT::Client::Impl::Impl(const std::string &host,
... ... @@ -40,13 +40,13 @@ TrueMQTT::Client::Impl::Impl(const std::string &amp;host,
40 40 std::chrono::milliseconds connection_backoff,
41 41 std::chrono::milliseconds connection_backoff_max,
42 42 std::chrono::milliseconds keep_alive_interval)
43   - : host(host),
44   - port(port),
45   - client_id(client_id),
46   - connection_timeout(connection_timeout),
47   - connection_backoff(connection_backoff),
48   - connection_backoff_max(connection_backoff_max),
49   - keep_alive_interval(keep_alive_interval)
  43 + : m_host(host),
  44 + m_port(port),
  45 + m_client_id(client_id),
  46 + m_connection_timeout(connection_timeout),
  47 + m_connection_backoff(connection_backoff),
  48 + m_connection_backoff_max(connection_backoff_max),
  49 + m_keep_alive_interval(keep_alive_interval)
50 50 {
51 51 }
52 52  
... ... @@ -56,112 +56,112 @@ TrueMQTT::Client::Impl::~Impl()
56 56  
57 57 void TrueMQTT::Client::setLogger(Client::LogLevel log_level, const std::function<void(Client::LogLevel, std::string)> &logger) const
58 58 {
59   - LOG_TRACE(this->m_impl, "Setting logger to log level " + std::to_string(log_level));
  59 + LOG_TRACE(m_impl, "Setting logger to log level " + std::to_string(log_level));
60 60  
61   - this->m_impl->log_level = log_level;
62   - this->m_impl->logger = logger;
  61 + m_impl->m_log_level = log_level;
  62 + m_impl->m_logger = logger;
63 63  
64   - LOG_DEBUG(this->m_impl, "Log level now on " + std::to_string(this->m_impl->log_level));
  64 + LOG_DEBUG(m_impl, "Log level now on " + std::to_string(m_impl->m_log_level));
65 65 }
66 66  
67 67 void TrueMQTT::Client::setLastWill(const std::string &topic, const std::string &payload, bool retain) const
68 68 {
69   - if (this->m_impl->state != Client::Impl::State::DISCONNECTED)
  69 + if (m_impl->m_state != Client::Impl::State::DISCONNECTED)
70 70 {
71   - LOG_ERROR(this->m_impl, "Cannot set last will when not disconnected");
  71 + LOG_ERROR(m_impl, "Cannot set last will when not disconnected");
72 72 return;
73 73 }
74 74  
75   - LOG_TRACE(this->m_impl, "Setting last will to topic " + topic + " with payload " + payload + " and retain " + std::to_string(retain));
  75 + LOG_TRACE(m_impl, "Setting last will to topic " + topic + " with payload " + payload + " and retain " + std::to_string(retain));
76 76  
77   - this->m_impl->last_will_topic = topic;
78   - this->m_impl->last_will_payload = payload;
79   - this->m_impl->last_will_retain = retain;
  77 + m_impl->m_last_will_topic = topic;
  78 + m_impl->m_last_will_payload = payload;
  79 + m_impl->m_last_will_retain = retain;
80 80 }
81 81  
82 82 void TrueMQTT::Client::setErrorCallback(const std::function<void(Error, std::string)> &callback) const
83 83 {
84   - LOG_TRACE(this->m_impl, "Setting error callback");
  84 + LOG_TRACE(m_impl, "Setting error callback");
85 85  
86   - this->m_impl->error_callback = callback;
  86 + m_impl->m_error_callback = callback;
87 87 }
88 88  
89 89 void TrueMQTT::Client::setPublishQueue(Client::PublishQueueType queue_type, size_t size) const
90 90 {
91   - if (this->m_impl->state != Client::Impl::State::DISCONNECTED)
  91 + if (m_impl->m_state != Client::Impl::State::DISCONNECTED)
92 92 {
93   - LOG_ERROR(this->m_impl, "Cannot set publish queue when not disconnected");
  93 + LOG_ERROR(m_impl, "Cannot set publish queue when not disconnected");
94 94 return;
95 95 }
96 96  
97   - LOG_TRACE(this->m_impl, "Setting publish queue to type " + std::to_string(queue_type) + " and size " + std::to_string(size));
  97 + LOG_TRACE(m_impl, "Setting publish queue to type " + std::to_string(queue_type) + " and size " + std::to_string(size));
98 98  
99   - this->m_impl->publish_queue_type = queue_type;
100   - this->m_impl->publish_queue_size = size;
  99 + m_impl->m_publish_queue_type = queue_type;
  100 + m_impl->m_publish_queue_size = size;
101 101 }
102 102  
103 103 void TrueMQTT::Client::connect() const
104 104 {
105   - std::scoped_lock lock(this->m_impl->state_mutex);
  105 + std::scoped_lock lock(m_impl->m_state_mutex);
106 106  
107   - if (this->m_impl->state != Client::Impl::State::DISCONNECTED)
  107 + if (m_impl->m_state != Client::Impl::State::DISCONNECTED)
108 108 {
109 109 return;
110 110 }
111 111  
112   - LOG_INFO(this->m_impl, "Connecting to " + this->m_impl->host + ":" + std::to_string(this->m_impl->port));
  112 + LOG_INFO(m_impl, "Connecting to " + m_impl->m_host + ":" + std::to_string(m_impl->m_port));
113 113  
114   - this->m_impl->state = Client::Impl::State::CONNECTING;
115   - this->m_impl->connect();
  114 + m_impl->m_state = Client::Impl::State::CONNECTING;
  115 + m_impl->connect();
116 116 }
117 117  
118 118 void TrueMQTT::Client::disconnect() const
119 119 {
120   - std::scoped_lock lock(this->m_impl->state_mutex);
  120 + std::scoped_lock lock(m_impl->m_state_mutex);
121 121  
122   - if (this->m_impl->state == Client::Impl::State::DISCONNECTED)
  122 + if (m_impl->m_state == Client::Impl::State::DISCONNECTED)
123 123 {
124   - LOG_TRACE(this->m_impl, "Already disconnected");
  124 + LOG_TRACE(m_impl, "Already disconnected");
125 125 return;
126 126 }
127 127  
128   - LOG_INFO(this->m_impl, "Disconnecting from broker");
  128 + LOG_INFO(m_impl, "Disconnecting from broker");
129 129  
130   - this->m_impl->state = Client::Impl::State::DISCONNECTED;
131   - this->m_impl->disconnect();
  130 + m_impl->m_state = Client::Impl::State::DISCONNECTED;
  131 + m_impl->disconnect();
132 132 }
133 133  
134 134 void TrueMQTT::Client::publish(const std::string &topic, const std::string &payload, bool retain) const
135 135 {
136   - std::scoped_lock lock(this->m_impl->state_mutex);
  136 + std::scoped_lock lock(m_impl->m_state_mutex);
137 137  
138   - LOG_DEBUG(this->m_impl, "Publishing message on topic '" + topic + "': " + payload + " (" + (retain ? "retained" : "not retained") + ")");
  138 + LOG_DEBUG(m_impl, "Publishing message on topic '" + topic + "': " + payload + " (" + (retain ? "retained" : "not retained") + ")");
139 139  
140   - switch (this->m_impl->state)
  140 + switch (m_impl->m_state)
141 141 {
142 142 case Client::Impl::State::DISCONNECTED:
143   - LOG_ERROR(this->m_impl, "Cannot publish when disconnected");
  143 + LOG_ERROR(m_impl, "Cannot publish when disconnected");
144 144 return;
145 145 case Client::Impl::State::CONNECTING:
146   - this->m_impl->toPublishQueue(topic, payload, retain);
  146 + m_impl->toPublishQueue(topic, payload, retain);
147 147 return;
148 148 case Client::Impl::State::CONNECTED:
149   - this->m_impl->sendPublish(topic, payload, retain);
  149 + m_impl->sendPublish(topic, payload, retain);
150 150 return;
151 151 }
152 152 }
153 153  
154 154 void TrueMQTT::Client::subscribe(const std::string &topic, const std::function<void(std::string, std::string)> &callback) const
155 155 {
156   - std::scoped_lock lock(this->m_impl->state_mutex);
  156 + std::scoped_lock lock(m_impl->m_state_mutex);
157 157  
158   - if (this->m_impl->state == Client::Impl::State::DISCONNECTED)
  158 + if (m_impl->m_state == Client::Impl::State::DISCONNECTED)
159 159 {
160   - LOG_ERROR(this->m_impl, "Cannot subscribe when disconnected");
  160 + LOG_ERROR(m_impl, "Cannot subscribe when disconnected");
161 161 return;
162 162 }
163 163  
164   - LOG_DEBUG(this->m_impl, "Subscribing to topic '" + topic + "'");
  164 + LOG_DEBUG(m_impl, "Subscribing to topic '" + topic + "'");
165 165  
166 166 // Split the topic on /, to find each part.
167 167 std::string part;
... ... @@ -169,7 +169,7 @@ void TrueMQTT::Client::subscribe(const std::string &amp;topic, const std::function&lt;v
169 169 std::getline(stopic, part, '/');
170 170  
171 171 // Find the root node, and walk down till we find the leaf node.
172   - Client::Impl::SubscriptionPart *subscriptions = &this->m_impl->subscriptions.try_emplace(part).first->second;
  172 + Client::Impl::SubscriptionPart *subscriptions = &m_impl->m_subscriptions.try_emplace(part).first->second;
173 173 while (std::getline(stopic, part, '/'))
174 174 {
175 175 subscriptions = &subscriptions->children.try_emplace(part).first->second;
... ... @@ -177,24 +177,24 @@ void TrueMQTT::Client::subscribe(const std::string &amp;topic, const std::function&lt;v
177 177 // Add the callback to the leaf node.
178 178 subscriptions->callbacks.push_back(callback);
179 179  
180   - this->m_impl->subscription_topics.insert(topic);
181   - if (this->m_impl->state == Client::Impl::State::CONNECTED)
  180 + m_impl->m_subscription_topics.insert(topic);
  181 + if (m_impl->m_state == Client::Impl::State::CONNECTED)
182 182 {
183   - this->m_impl->sendSubscribe(topic);
  183 + m_impl->sendSubscribe(topic);
184 184 }
185 185 }
186 186  
187 187 void TrueMQTT::Client::unsubscribe(const std::string &topic) const
188 188 {
189   - std::scoped_lock lock(this->m_impl->state_mutex);
  189 + std::scoped_lock lock(m_impl->m_state_mutex);
190 190  
191   - if (this->m_impl->state == Client::Impl::State::DISCONNECTED)
  191 + if (m_impl->m_state == Client::Impl::State::DISCONNECTED)
192 192 {
193   - LOG_ERROR(this->m_impl, "Cannot unsubscribe when disconnected");
  193 + LOG_ERROR(m_impl, "Cannot unsubscribe when disconnected");
194 194 return;
195 195 }
196 196  
197   - LOG_DEBUG(this->m_impl, "Unsubscribing from topic '" + topic + "'");
  197 + LOG_DEBUG(m_impl, "Unsubscribing from topic '" + topic + "'");
198 198  
199 199 // Split the topic on /, to find each part.
200 200 std::string part;
... ... @@ -203,7 +203,7 @@ void TrueMQTT::Client::unsubscribe(const std::string &amp;topic) const
203 203  
204 204 // Find the root node, and walk down till we find the leaf node.
205 205 std::vector<std::tuple<std::string, Client::Impl::SubscriptionPart *>> reverse;
206   - Client::Impl::SubscriptionPart *subscriptions = &this->m_impl->subscriptions[part];
  206 + Client::Impl::SubscriptionPart *subscriptions = &m_impl->m_subscriptions[part];
207 207 reverse.emplace_back(part, subscriptions);
208 208 while (std::getline(stopic, part, '/'))
209 209 {
... ... @@ -232,25 +232,25 @@ void TrueMQTT::Client::unsubscribe(const std::string &amp;topic) const
232 232 }
233 233 if (!remove_next.empty())
234 234 {
235   - this->m_impl->subscriptions.erase(remove_next);
  235 + m_impl->m_subscriptions.erase(remove_next);
236 236 }
237 237  
238   - this->m_impl->subscription_topics.erase(topic);
239   - if (this->m_impl->state == Client::Impl::State::CONNECTED)
  238 + m_impl->m_subscription_topics.erase(topic);
  239 + if (m_impl->m_state == Client::Impl::State::CONNECTED)
240 240 {
241   - this->m_impl->sendUnsubscribe(topic);
  241 + m_impl->sendUnsubscribe(topic);
242 242 }
243 243 }
244 244  
245 245 void TrueMQTT::Client::Impl::connectionStateChange(bool connected)
246 246 {
247   - std::scoped_lock lock(this->state_mutex);
  247 + std::scoped_lock lock(m_state_mutex);
248 248  
249 249 if (connected)
250 250 {
251 251 LOG_INFO(this, "Connected to broker");
252 252  
253   - this->state = Client::Impl::State::CONNECTED;
  253 + m_state = Client::Impl::State::CONNECTED;
254 254  
255 255 // Restoring subscriptions and flushing the queue is done while still under
256 256 // the lock. This to prevent \ref disconnect from being called while we are
... ... @@ -261,55 +261,55 @@ void TrueMQTT::Client::Impl::connectionStateChange(bool connected)
261 261 // implementation.
262 262  
263 263 // First restore any subscription.
264   - for (auto &subscription : this->subscription_topics)
  264 + for (auto &subscription : m_subscription_topics)
265 265 {
266   - this->sendSubscribe(subscription);
  266 + sendSubscribe(subscription);
267 267 }
268 268 // Flush the publish queue.
269   - for (const auto &[topic, payload, retain] : this->publish_queue)
  269 + for (const auto &[topic, payload, retain] : m_publish_queue)
270 270 {
271   - this->sendPublish(topic, payload, retain);
  271 + sendPublish(topic, payload, retain);
272 272 }
273   - this->publish_queue.clear();
  273 + m_publish_queue.clear();
274 274 }
275 275 else
276 276 {
277 277 LOG_INFO(this, "Disconnected from broker");
278   - this->state = Client::Impl::State::CONNECTING;
  278 + m_state = Client::Impl::State::CONNECTING;
279 279 }
280 280 }
281 281  
282 282 void TrueMQTT::Client::Impl::toPublishQueue(const std::string &topic, const std::string &payload, bool retain)
283 283 {
284   - if (this->state != Client::Impl::State::CONNECTING)
  284 + if (m_state != Client::Impl::State::CONNECTING)
285 285 {
286 286 LOG_ERROR(this, "Cannot queue publish message when not connecting");
287 287 return;
288 288 }
289 289  
290   - switch (this->publish_queue_type)
  290 + switch (m_publish_queue_type)
291 291 {
292 292 case Client::PublishQueueType::DROP:
293 293 LOG_WARNING(this, "Publish queue is disabled, dropping message");
294 294 return;
295 295 case Client::PublishQueueType::FIFO:
296   - if (this->publish_queue.size() >= this->publish_queue_size)
  296 + if (m_publish_queue.size() >= m_publish_queue_size)
297 297 {
298 298 LOG_WARNING(this, "Publish queue is full, dropping oldest message on queue");
299   - this->publish_queue.pop_front();
  299 + m_publish_queue.pop_front();
300 300 }
301 301 break;
302 302 case Client::PublishQueueType::LIFO:
303   - if (this->publish_queue.size() >= this->publish_queue_size)
  303 + if (m_publish_queue.size() >= m_publish_queue_size)
304 304 {
305 305 LOG_WARNING(this, "Publish queue is full, dropping newest message on queue");
306   - this->publish_queue.pop_back();
  306 + m_publish_queue.pop_back();
307 307 }
308 308 break;
309 309 }
310 310  
311 311 LOG_TRACE(this, "Adding message to publish queue");
312   - this->publish_queue.emplace_back(topic, payload, retain);
  312 + m_publish_queue.emplace_back(topic, payload, retain);
313 313 }
314 314  
315 315 void TrueMQTT::Client::Impl::findSubscriptionMatch(std::vector<std::function<void(std::string, std::string)>> &matching_callbacks, const std::map<std::string, Client::Impl::SubscriptionPart> &subscriptions, std::deque<std::string> &parts)
... ... @@ -372,7 +372,7 @@ void TrueMQTT::Client::Impl::messageReceived(std::string topic, std::string payl
372 372  
373 373 // Find the matching subscription(s) with recursion.
374 374 std::vector<std::function<void(std::string, std::string)>> matching_callbacks;
375   - findSubscriptionMatch(matching_callbacks, subscriptions, parts);
  375 + findSubscriptionMatch(matching_callbacks, m_subscriptions, parts);
376 376  
377 377 LOG_TRACE(this, "Found " + std::to_string(matching_callbacks.size()) + " subscription(s) for topic '" + topic + "'");
378 378  
... ...
src/ClientImpl.h
... ... @@ -56,34 +56,34 @@ public:
56 56  
57 57 void findSubscriptionMatch(std::vector<std::function<void(std::string, std::string)>> &callbacks, const std::map<std::string, SubscriptionPart> &subscriptions, std::deque<std::string> &parts); ///< Recursive function to find any matching subscription based on parts.
58 58  
59   - State state = State::DISCONNECTED; ///< The current state of the client.
60   - std::mutex state_mutex; ///< Mutex to protect state changes.
  59 + State m_state = State::DISCONNECTED; ///< The current state of the client.
  60 + std::mutex m_state_mutex; ///< Mutex to protect state changes.
61 61  
62   - std::string host; ///< Host of the broker.
63   - int port; ///< Port of the broker.
64   - std::string client_id; ///< Client ID to use when connecting to the broker.
65   - std::chrono::milliseconds connection_timeout; ///< Timeout in seconds for the connection to the broker.
66   - 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.
67   - std::chrono::milliseconds connection_backoff_max; ///< Maximum time between backoff attempts in seconds.
68   - std::chrono::milliseconds keep_alive_interval; ///< Interval in seconds between keep-alive messages.
  62 + std::string m_host; ///< Host of the broker.
  63 + int m_port; ///< Port of the broker.
  64 + std::string m_client_id; ///< Client ID to use when connecting to the broker.
  65 + std::chrono::milliseconds m_connection_timeout; ///< Timeout in seconds for the connection to the broker.
  66 + 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.
  67 + std::chrono::milliseconds m_connection_backoff_max; ///< Maximum time between backoff attempts in seconds.
  68 + std::chrono::milliseconds m_keep_alive_interval; ///< Interval in seconds between keep-alive messages.
69 69  
70   - Client::LogLevel log_level = Client::LogLevel::NONE; ///< The log level to use.
71   - std::function<void(Client::LogLevel, std::string)> logger = [](Client::LogLevel, std::string) { /* empty */ }; ///< Logger callback.
  70 + Client::LogLevel m_log_level = Client::LogLevel::NONE; ///< The log level to use.
  71 + std::function<void(Client::LogLevel, std::string)> m_logger = [](Client::LogLevel, std::string) { /* empty */ }; ///< Logger callback.
72 72  
73   - std::string last_will_topic = ""; ///< Topic to publish the last will message to.
74   - std::string last_will_payload = ""; ///< Payload of the last will message.
75   - bool last_will_retain = false; ///< Whether to retain the last will message.
  73 + std::string m_last_will_topic = ""; ///< Topic to publish the last will message to.
  74 + std::string m_last_will_payload = ""; ///< Payload of the last will message.
  75 + bool m_last_will_retain = false; ///< Whether to retain the last will message.
76 76  
77   - std::function<void(Error, std::string)> error_callback = [](Error, std::string) { /* empty */ }; ///< Error callback.
  77 + std::function<void(Error, std::string)> m_error_callback = [](Error, std::string) { /* empty */ }; ///< Error callback.
78 78  
79   - Client::PublishQueueType publish_queue_type = Client::PublishQueueType::DROP; ///< The type of queue to use for the publish queue.
80   - size_t publish_queue_size = -1; ///< Size of the publish queue.
81   - std::deque<std::tuple<std::string, std::string, bool>> publish_queue; ///< Queue of publish messages to send to the broker.
  79 + Client::PublishQueueType m_publish_queue_type = Client::PublishQueueType::DROP; ///< The type of queue to use for the publish queue.
  80 + size_t m_publish_queue_size = -1; ///< Size of the publish queue.
  81 + std::deque<std::tuple<std::string, std::string, bool>> m_publish_queue; ///< Queue of publish messages to send to the broker.
82 82  
83   - std::set<std::string> subscription_topics; ///< Flat list of topics the client is subscribed to.
84   - std::map<std::string, SubscriptionPart> subscriptions; ///< Tree of active subscriptions build up from the parts on the topic.
  83 + std::set<std::string> m_subscription_topics; ///< Flat list of topics the client is subscribed to.
  84 + std::map<std::string, SubscriptionPart> m_subscriptions; ///< Tree of active subscriptions build up from the parts on the topic.
85 85  
86 86 class Connection;
87   - std::unique_ptr<Connection> connection; ///< Connection to the broker.
88   - uint16_t packet_id = 0; ///< The next packet ID to use. Will overflow on 65535 to 0.
  87 + std::unique_ptr<Connection> m_connection; ///< Connection to the broker.
  88 + uint16_t m_packet_id = 0; ///< The next packet ID to use. Will overflow on 65535 to 0.
89 89 };
... ...
src/Connection.cpp
... ... @@ -19,7 +19,7 @@
19 19 TrueMQTT::Client::Impl::Connection::Connection(Client::Impl &impl)
20 20 : m_impl(impl),
21 21 m_thread(&Connection::run, this),
22   - m_backoff(impl.connection_backoff)
  22 + m_backoff(impl.m_connection_backoff)
23 23 {
24 24 }
25 25  
... ... @@ -35,10 +35,10 @@ TrueMQTT::Client::Impl::Connection::~Connection()
35 35  
36 36 // freeaddrinfo() is one of those functions that doesn't take kind to NULL pointers
37 37 // on some platforms.
38   - if (this->m_host_resolved != nullptr)
  38 + if (m_host_resolved != nullptr)
39 39 {
40   - freeaddrinfo(this->m_host_resolved);
41   - this->m_host_resolved = nullptr;
  40 + freeaddrinfo(m_host_resolved);
  41 + m_host_resolved = nullptr;
42 42 }
43 43 }
44 44  
... ... @@ -74,9 +74,9 @@ void TrueMQTT::Client::Impl::Connection::run()
74 74  
75 75 // Calculate the next backoff time, slowly reducing how often we retry.
76 76 m_backoff *= 2;
77   - if (m_backoff > m_impl.connection_backoff_max)
  77 + if (m_backoff > m_impl.m_connection_backoff_max)
78 78 {
79   - m_backoff = m_impl.connection_backoff_max;
  79 + m_backoff = m_impl.m_connection_backoff_max;
80 80 }
81 81  
82 82 m_state = State::RESOLVING;
... ... @@ -126,19 +126,19 @@ void TrueMQTT::Client::Impl::Connection::resolve()
126 126 hints.ai_flags = AI_ADDRCONFIG;
127 127  
128 128 // If we resolved previously, free the result.
129   - if (this->m_host_resolved != nullptr)
  129 + if (m_host_resolved != nullptr)
130 130 {
131   - freeaddrinfo(this->m_host_resolved);
132   - this->m_host_resolved = nullptr;
  131 + freeaddrinfo(m_host_resolved);
  132 + m_host_resolved = nullptr;
133 133 }
134 134  
135 135 // Request the OS to resolve the hostname into an IP address.
136 136 // We do this even if the hostname is already an IP address, as that
137 137 // makes for far easier code.
138   - int error = getaddrinfo(m_impl.host.c_str(), std::to_string(m_impl.port).c_str(), &hints, &m_host_resolved);
  138 + int error = getaddrinfo(m_impl.m_host.c_str(), std::to_string(m_impl.m_port).c_str(), &hints, &m_host_resolved);
139 139 if (error != 0)
140 140 {
141   - m_impl.error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string(gai_strerror(error)));
  141 + m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, std::string(gai_strerror(error)));
142 142 return;
143 143 }
144 144  
... ... @@ -146,7 +146,7 @@ void TrueMQTT::Client::Impl::Connection::resolve()
146 146 // IPv6.
147 147 std::deque<addrinfo *> addresses_ipv4;
148 148 std::deque<addrinfo *> addresses_ipv6;
149   - for (addrinfo *ai = this->m_host_resolved; ai != nullptr; ai = ai->ai_next)
  149 + for (addrinfo *ai = m_host_resolved; ai != nullptr; ai = ai->ai_next)
150 150 {
151 151 if (ai->ai_family == AF_INET6)
152 152 {
... ... @@ -181,9 +181,9 @@ void TrueMQTT::Client::Impl::Connection::resolve()
181 181  
182 182 #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_DEBUG
183 183 // For debugging, print the addresses we resolved into.
184   - if (m_impl.log_level >= TrueMQTT::Client::LogLevel::DEBUG)
  184 + if (m_impl.m_log_level >= TrueMQTT::Client::LogLevel::DEBUG)
185 185 {
186   - LOG_DEBUG(&m_impl, "Resolved hostname '" + m_impl.host + "' to:");
  186 + LOG_DEBUG(&m_impl, "Resolved hostname '" + m_impl.m_host + "' to:");
187 187 for (const addrinfo *res : m_addresses)
188 188 {
189 189 LOG_DEBUG(&m_impl, "- " + addrinfoToString(res));
... ... @@ -194,7 +194,7 @@ void TrueMQTT::Client::Impl::Connection::resolve()
194 194 // In some odd cases, the list can be empty. This is a fatal error.
195 195 if (m_addresses.empty())
196 196 {
197   - m_impl.error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, "");
  197 + m_impl.m_error_callback(TrueMQTT::Client::Error::HOSTNAME_LOOKUP_FAILED, "");
198 198 return;
199 199 }
200 200  
... ... @@ -255,7 +255,7 @@ bool TrueMQTT::Client::Impl::Connection::connectToAny()
255 255 }
256 256  
257 257 // Check if it is more than the timeout ago since we last tried a connection.
258   - if (std::chrono::steady_clock::now() < m_last_attempt + m_impl.connection_timeout)
  258 + if (std::chrono::steady_clock::now() < m_last_attempt + m_impl.m_connection_timeout)
259 259 {
260 260 return true;
261 261 }
... ... @@ -328,7 +328,7 @@ bool TrueMQTT::Client::Impl::Connection::connectToAny()
328 328 LOG_WARNING(&m_impl, "Could not set socket to non-blocking; expect performance impact");
329 329 }
330 330  
331   - m_backoff = m_impl.connection_backoff;
  331 + m_backoff = m_impl.m_connection_backoff;
332 332 m_socket = socket_connected;
333 333  
334 334 // 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)
398 398  
399 399 void TrueMQTT::Client::Impl::connect()
400 400 {
401   - this->connection = std::make_unique<Connection>(*this);
  401 + m_connection = std::make_unique<Connection>(*this);
402 402 }
403 403  
404 404 void TrueMQTT::Client::Impl::disconnect()
405 405 {
406   - this->subscriptions.clear();
407   - this->publish_queue.clear();
  406 + m_subscriptions.clear();
  407 + m_publish_queue.clear();
408 408  
409   - this->connection.reset();
  409 + m_connection.reset();
410 410 }
... ...
src/Log.h
... ... @@ -22,65 +22,65 @@
22 22 #endif
23 23  
24 24 #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_ERROR
25   -#define LOG_ERROR(obj, x) \
26   - do \
27   - { \
28   - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::ERROR) \
29   - { \
30   - (obj)->logger(TrueMQTT::Client::LogLevel::ERROR, x); \
31   - } \
  25 +#define LOG_ERROR(obj, x) \
  26 + do \
  27 + { \
  28 + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::ERROR) \
  29 + { \
  30 + (obj)->m_logger(TrueMQTT::Client::LogLevel::ERROR, x); \
  31 + } \
32 32 } while (0)
33 33 #else
34 34 #define LOG_ERROR(obj, x)
35 35 #endif
36 36  
37 37 #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_WARNING
38   -#define LOG_WARNING(obj, x) \
39   - do \
40   - { \
41   - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::WARNING) \
42   - { \
43   - (obj)->logger(TrueMQTT::Client::LogLevel::WARNING, x); \
44   - } \
  38 +#define LOG_WARNING(obj, x) \
  39 + do \
  40 + { \
  41 + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::WARNING) \
  42 + { \
  43 + (obj)->m_logger(TrueMQTT::Client::LogLevel::WARNING, x); \
  44 + } \
45 45 } while (0)
46 46 #else
47 47 #define LOG_WARNING(obj, x)
48 48 #endif
49 49  
50 50 #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_INFO
51   -#define LOG_INFO(obj, x) \
52   - do \
53   - { \
54   - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::INFO) \
55   - { \
56   - (obj)->logger(TrueMQTT::Client::LogLevel::INFO, x); \
57   - } \
  51 +#define LOG_INFO(obj, x) \
  52 + do \
  53 + { \
  54 + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::INFO) \
  55 + { \
  56 + (obj)->m_logger(TrueMQTT::Client::LogLevel::INFO, x); \
  57 + } \
58 58 } while (0)
59 59 #else
60 60 #define LOG_INFO(obj, x)
61 61 #endif
62 62  
63 63 #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_DEBUG
64   -#define LOG_DEBUG(obj, x) \
65   - do \
66   - { \
67   - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::DEBUG) \
68   - { \
69   - (obj)->logger(TrueMQTT::Client::LogLevel::DEBUG, x); \
70   - } \
  64 +#define LOG_DEBUG(obj, x) \
  65 + do \
  66 + { \
  67 + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::DEBUG) \
  68 + { \
  69 + (obj)->m_logger(TrueMQTT::Client::LogLevel::DEBUG, x); \
  70 + } \
71 71 } while (0)
72 72 #else
73 73 #define LOG_DEBUG(obj, x)
74 74 #endif
75 75  
76 76 #if MIN_LOGGER_LEVEL >= LOGGER_LEVEL_TRACE
77   -#define LOG_TRACE(obj, x) \
78   - do \
79   - { \
80   - if ((obj)->log_level >= TrueMQTT::Client::LogLevel::TRACE) \
81   - { \
82   - (obj)->logger(TrueMQTT::Client::LogLevel::TRACE, x); \
83   - } \
  77 +#define LOG_TRACE(obj, x) \
  78 + do \
  79 + { \
  80 + if ((obj)->m_log_level >= TrueMQTT::Client::LogLevel::TRACE) \
  81 + { \
  82 + (obj)->m_logger(TrueMQTT::Client::LogLevel::TRACE, x); \
  83 + } \
84 84 } while (0)
85 85 #else
86 86 #define LOG_TRACE(obj, x)
... ...
src/Packet.cpp
... ... @@ -295,7 +295,7 @@ bool TrueMQTT::Client::Impl::Connection::recvLoop()
295 295 {
296 296 LOG_WARNING(&m_impl, "Broker refused our subscription");
297 297 // TODO -- Keep track of the topic per ticket
298   - m_impl.error_callback(TrueMQTT::Client::Error::SUBSCRIBE_FAILED, "");
  298 + m_impl.m_error_callback(TrueMQTT::Client::Error::SUBSCRIBE_FAILED, "");
299 299 }
300 300  
301 301 break;
... ... @@ -396,7 +396,7 @@ void TrueMQTT::Client::Impl::sendPublish(const std::string &amp;topic, const std::st
396 396 packet.write_string(topic);
397 397 packet.write(payload.c_str(), payload.size());
398 398  
399   - connection->send(packet);
  399 + m_connection->send(packet);
400 400 }
401 401  
402 402 void TrueMQTT::Client::Impl::sendSubscribe(const std::string &topic)
... ... @@ -406,16 +406,16 @@ void TrueMQTT::Client::Impl::sendSubscribe(const std::string &amp;topic)
406 406 Packet packet(Packet::PacketType::SUBSCRIBE, 2);
407 407  
408 408 // By specs, packet-id zero is not allowed.
409   - if (packet_id == 0)
  409 + if (m_packet_id == 0)
410 410 {
411   - packet_id++;
  411 + m_packet_id++;
412 412 }
413 413  
414   - packet.write_uint16(packet_id++);
  414 + packet.write_uint16(m_packet_id++);
415 415 packet.write_string(topic);
416 416 packet.write_uint8(0); // QoS
417 417  
418   - connection->send(packet);
  418 + m_connection->send(packet);
419 419 }
420 420  
421 421 void TrueMQTT::Client::Impl::sendUnsubscribe(const std::string &topic)
... ... @@ -425,13 +425,13 @@ void TrueMQTT::Client::Impl::sendUnsubscribe(const std::string &amp;topic)
425 425 Packet packet(Packet::PacketType::UNSUBSCRIBE, 2);
426 426  
427 427 // By specs, packet-id zero is not allowed.
428   - if (packet_id == 0)
  428 + if (m_packet_id == 0)
429 429 {
430   - packet_id++;
  430 + m_packet_id++;
431 431 }
432 432  
433   - packet.write_uint16(packet_id++);
  433 + packet.write_uint16(m_packet_id++);
434 434 packet.write_string(topic);
435 435  
436   - connection->send(packet);
  436 + m_connection->send(packet);
437 437 }
... ...