Commit 199d70751cd1e2b7fd66a5f1f044b62b982fc83b
1 parent
e8b2b36e
implement logging to mqttclient
Showing
6 changed files
with
41 additions
and
77 deletions
CMakeLists.txt
| 1 | cmake_minimum_required(VERSION 3.0) | 1 | cmake_minimum_required(VERSION 3.0) |
| 2 | project(osdev_mqtt) | 2 | project(osdev_mqtt) |
| 3 | -# ============================================================================== | ||
| 4 | -# Check to see if we're a submodule or top-repo. | ||
| 5 | -if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | ||
| 6 | - message( STATUS "Looks like we're a single module" ) | ||
| 7 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) | ||
| 8 | -elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) | ||
| 9 | - message( STATUS "Looks like we're a submodule" ) | ||
| 10 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) | ||
| 11 | -else() | ||
| 12 | - message( FATAL_ERROR "No cmake directory found. Did you run the submodules script?" ) | ||
| 13 | -endif() | ||
| 14 | - | ||
| 15 | -# ============================================================================== | ||
| 16 | -# Check to see if there is versioning information available | ||
| 17 | -if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/versioning) | ||
| 18 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/versioning/cmake) | ||
| 19 | -elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../versioning) | ||
| 20 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../versioning/cmake) | ||
| 21 | -else() | ||
| 22 | - message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" ) | ||
| 23 | -endif() | 3 | +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/submodules/cmake) |
| 24 | 4 | ||
| 25 | # ============================================================================== | 5 | # ============================================================================== |
| 26 | # = Include build information | 6 | # = Include build information |
| 27 | -include(osdevversion) | ||
| 28 | include(projectheader) | 7 | include(projectheader) |
| 29 | - | ||
| 30 | project_header(osdev_mqtt) | 8 | project_header(osdev_mqtt) |
| 31 | 9 | ||
| 10 | +add_subdirectory(submodules/logger) | ||
| 32 | add_subdirectory(src) | 11 | add_subdirectory(src) |
| 33 | add_subdirectory(examples/pub) | 12 | add_subdirectory(examples/pub) |
| 34 | add_subdirectory(examples/sub) | 13 | add_subdirectory(examples/sub) |
| 35 | 14 | ||
| 36 | include(packaging) | 15 | include(packaging) |
| 37 | package_component() | 16 | package_component() |
| 38 | - | ||
| 39 | -# add_subdirectory(test) |
examples/pub/CMakeLists.txt
| 1 | cmake_minimum_required(VERSION 3.0) | 1 | cmake_minimum_required(VERSION 3.0) |
| 2 | -LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake) | 2 | +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/submodules/cmake) |
| 3 | 3 | ||
| 4 | include(projectheader) | 4 | include(projectheader) |
| 5 | project_header(test_mqtt_pub) | 5 | project_header(test_mqtt_pub) |
| @@ -27,7 +27,7 @@ target_link_libraries( | @@ -27,7 +27,7 @@ target_link_libraries( | ||
| 27 | set_target_properties( ${PROJECT_NAME} PROPERTIES | 27 | set_target_properties( ${PROJECT_NAME} PROPERTIES |
| 28 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin | 28 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin |
| 29 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib | 29 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib |
| 30 | - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive | 30 | + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib |
| 31 | ) | 31 | ) |
| 32 | 32 | ||
| 33 | include(installation) | 33 | include(installation) |
examples/sub/CMakeLists.txt
| 1 | cmake_minimum_required(VERSION 3.0) | 1 | cmake_minimum_required(VERSION 3.0) |
| 2 | -LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake) | 2 | +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/submodules/cmake) |
| 3 | 3 | ||
| 4 | include(projectheader) | 4 | include(projectheader) |
| 5 | project_header(test_mqtt_sub) | 5 | project_header(test_mqtt_sub) |
src/CMakeLists.txt
| 1 | cmake_minimum_required(VERSION 3.12) | 1 | cmake_minimum_required(VERSION 3.12) |
| 2 | -# ============================================================================== | ||
| 3 | -# Check to see if we're a submodule or top-repo. | ||
| 4 | -if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) | ||
| 5 | - message( STATUS "Looks like we're a single module" ) | ||
| 6 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) | ||
| 7 | -elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake) | ||
| 8 | - message( STATUS "Looks like we're a submodule" ) | ||
| 9 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake) | ||
| 10 | -else() | ||
| 11 | - message( FATAL_ERROR "No cmake directory found. Did you run the submodules script?" ) | ||
| 12 | -endif() | 2 | +LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/submodules/cmake) |
| 13 | 3 | ||
| 14 | -# ============================================================================== | ||
| 15 | -# Check to see if there is versioning information available | ||
| 16 | -if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../versioning) | ||
| 17 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../versioning/cmake) | ||
| 18 | -elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../versioning) | ||
| 19 | - LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../versioning/cmake) | ||
| 20 | -else() | ||
| 21 | - message( FATAL_ERROR "No ${CURRENT_SOURCE_DIR}/osdev_versioning directory found. Did you run the submodules script?" ) | ||
| 22 | -endif() | ||
| 23 | -# ============================================================================== | ||
| 24 | include(projectheader) | 4 | include(projectheader) |
| 25 | - | ||
| 26 | project_header(mqtt-cpp) | 5 | project_header(mqtt-cpp) |
| 27 | 6 | ||
| 28 | find_package( Boost REQUIRED COMPONENTS regex ) | 7 | find_package( Boost REQUIRED COMPONENTS regex ) |
| @@ -31,6 +10,7 @@ include(compiler) | @@ -31,6 +10,7 @@ include(compiler) | ||
| 31 | 10 | ||
| 32 | include_directories( | 11 | include_directories( |
| 33 | ${CMAKE_SOURCE_DIR}/include | 12 | ${CMAKE_SOURCE_DIR}/include |
| 13 | + ${CMAKE_SOURCE_DIR}/submodules/logger/src | ||
| 34 | ) | 14 | ) |
| 35 | 15 | ||
| 36 | set(SRC_LIST | 16 | set(SRC_LIST |
| @@ -67,6 +47,7 @@ add_libraries( | @@ -67,6 +47,7 @@ add_libraries( | ||
| 67 | Boost::boost | 47 | Boost::boost |
| 68 | Boost::regex | 48 | Boost::regex |
| 69 | paho-mqtt3a | 49 | paho-mqtt3a |
| 50 | + ${CMAKE_SOURCE_DIR}/build/lib/liblogger.a | ||
| 70 | ) | 51 | ) |
| 71 | 52 | ||
| 72 | include(installation) | 53 | include(installation) |
src/mqttclient.cpp
| @@ -21,6 +21,9 @@ | @@ -21,6 +21,9 @@ | ||
| 21 | * ***************************************************************************/ | 21 | * ***************************************************************************/ |
| 22 | #include "mqttclient.h" | 22 | #include "mqttclient.h" |
| 23 | 23 | ||
| 24 | +// osdev::components::logger | ||
| 25 | +#include "log.h" | ||
| 26 | + | ||
| 24 | // osdev::components::mqtt | 27 | // osdev::components::mqtt |
| 25 | #include "clientpaho.h" | 28 | #include "clientpaho.h" |
| 26 | #include "mqttutil.h" | 29 | #include "mqttutil.h" |
| @@ -32,8 +35,10 @@ | @@ -32,8 +35,10 @@ | ||
| 32 | // std | 35 | // std |
| 33 | #include <numeric> | 36 | #include <numeric> |
| 34 | #include <iostream> | 37 | #include <iostream> |
| 38 | +#include <string> | ||
| 35 | 39 | ||
| 36 | using namespace osdev::components::mqtt; | 40 | using namespace osdev::components::mqtt; |
| 41 | +using namespace osdev::components::log; | ||
| 37 | 42 | ||
| 38 | namespace { | 43 | namespace { |
| 39 | /** | 44 | /** |
| @@ -63,6 +68,8 @@ MqttClient::MqttClient(const std::string& _clientId, const std::function<void(co | @@ -63,6 +68,8 @@ MqttClient::MqttClient(const std::string& _clientId, const std::function<void(co | ||
| 63 | , m_eventQueue(_clientId) | 68 | , m_eventQueue(_clientId) |
| 64 | , m_workerThread( std::thread( &MqttClient::eventHandler, this ) ) | 69 | , m_workerThread( std::thread( &MqttClient::eventHandler, this ) ) |
| 65 | { | 70 | { |
| 71 | + Log::init( "mqtt-library" ); | ||
| 72 | + LogInfo( "MQTT Client started", "[MqttClient::MqttClient]"); | ||
| 66 | } | 73 | } |
| 67 | 74 | ||
| 68 | MqttClient::~MqttClient() | 75 | MqttClient::~MqttClient() |
| @@ -73,16 +80,16 @@ MqttClient::~MqttClient() | @@ -73,16 +80,16 @@ MqttClient::~MqttClient() | ||
| 73 | decltype(m_principalClient) principalClient{}; | 80 | decltype(m_principalClient) principalClient{}; |
| 74 | 81 | ||
| 75 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); | 82 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); |
| 76 | - // LogDebug( "MqttClient", std::string( m_clientId + " - cleanup principal client" ) ); | 83 | + LogDebug( "MqttClient", std::string( m_clientId + " - cleanup principal client" ) ); |
| 77 | m_principalClient.swap(principalClient); | 84 | m_principalClient.swap(principalClient); |
| 78 | } | 85 | } |
| 79 | 86 | ||
| 80 | - // LogDebug( "MqttClient", std::string( m_clientId + " - dtor stop queue" ) ); | 87 | + LogDebug( "MqttClient", std::string( m_clientId + " - dtor stop queue" ) ); |
| 81 | m_eventQueue.stop(); | 88 | m_eventQueue.stop(); |
| 82 | if (m_workerThread.joinable()) { | 89 | if (m_workerThread.joinable()) { |
| 83 | m_workerThread.join(); | 90 | m_workerThread.join(); |
| 84 | } | 91 | } |
| 85 | - // LogDebug( "MqttClient", std::string( m_clientId + " - dtor ready" ) ); | 92 | + LogDebug( "MqttClient", std::string( m_clientId + " - dtor ready" ) ); |
| 86 | } | 93 | } |
| 87 | 94 | ||
| 88 | std::string MqttClient::clientId() const | 95 | std::string MqttClient::clientId() const |
| @@ -133,7 +140,7 @@ void MqttClient::connect(const std::string& host, int port, const Credentials& c | @@ -133,7 +140,7 @@ void MqttClient::connect(const std::string& host, int port, const Credentials& c | ||
| 133 | 140 | ||
| 134 | void MqttClient::connect(const std::string& _endpoint) | 141 | void MqttClient::connect(const std::string& _endpoint) |
| 135 | { | 142 | { |
| 136 | - // LogInfo( "MqttClient", std::string( m_clientId + " - Request connect" ) ); | 143 | + LogInfo( "MqttClient", std::string( m_clientId + " - Request connect" ) ); |
| 137 | 144 | ||
| 138 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); | 145 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); |
| 139 | IMqttClientImpl* client(nullptr); | 146 | IMqttClientImpl* client(nullptr); |
| @@ -147,7 +154,7 @@ void MqttClient::connect(const std::string& _endpoint) | @@ -147,7 +154,7 @@ void MqttClient::connect(const std::string& _endpoint) | ||
| 147 | } | 154 | } |
| 148 | else | 155 | else |
| 149 | { | 156 | { |
| 150 | - // LogError( "MqttClient", std::string( m_clientId + " - Cannot connect to different endpoint. Disconnect first." ) ); | 157 | + LogError( "MqttClient", std::string( m_clientId + " - Cannot connect to different endpoint. Disconnect first." ) ); |
| 151 | return; | 158 | return; |
| 152 | } | 159 | } |
| 153 | } | 160 | } |
| @@ -167,7 +174,7 @@ void MqttClient::connect(const std::string& _endpoint) | @@ -167,7 +174,7 @@ void MqttClient::connect(const std::string& _endpoint) | ||
| 167 | 174 | ||
| 168 | void MqttClient::disconnect() | 175 | void MqttClient::disconnect() |
| 169 | { | 176 | { |
| 170 | - // LogInfo( "MqttClient", std::string( m_clientId + " - Request disconnect" ) ); | 177 | + LogInfo( "MqttClient", std::string( m_clientId + " - Request disconnect" ) ); |
| 171 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); | 178 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); |
| 172 | 179 | ||
| 173 | decltype(m_additionalClients) additionalClients{}; | 180 | decltype(m_additionalClients) additionalClients{}; |
| @@ -176,6 +183,7 @@ void MqttClient::disconnect() | @@ -176,6 +183,7 @@ void MqttClient::disconnect() | ||
| 176 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); | 183 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); |
| 177 | if (!m_principalClient || m_principalClient->connectionStatus() == ConnectionStatus::Disconnected || m_principalClient->connectionStatus() == ConnectionStatus::DisconnectInProgress) | 184 | if (!m_principalClient || m_principalClient->connectionStatus() == ConnectionStatus::Disconnected || m_principalClient->connectionStatus() == ConnectionStatus::DisconnectInProgress) |
| 178 | { | 185 | { |
| 186 | + LogDebug( "MqttClient", std::string( m_clientId + " - Principal client not connected" ) ); | ||
| 179 | return; | 187 | return; |
| 180 | } | 188 | } |
| 181 | m_additionalClients.swap( additionalClients ); | 189 | m_additionalClients.swap( additionalClients ); |
| @@ -188,8 +196,7 @@ void MqttClient::disconnect() | @@ -188,8 +196,7 @@ void MqttClient::disconnect() | ||
| 188 | } | 196 | } |
| 189 | 197 | ||
| 190 | 198 | ||
| 191 | - // LogDebug( "MqttClient", std::string( m_clientId + " - Unsubscribe and disconnect clients" ) ); | ||
| 192 | - // DebugLogToFIle ("MqttClient", "%1 - Unsubscribe and disconnect clients", m_clientId); | 199 | + LogDebug( "MqttClient", std::string( m_clientId + " - Unsubscribe and disconnect clients" ) ); |
| 193 | for ( auto& cl : clients ) | 200 | for ( auto& cl : clients ) |
| 194 | { | 201 | { |
| 195 | cl->unsubscribeAll(); | 202 | cl->unsubscribeAll(); |
| @@ -215,15 +222,15 @@ Token MqttClient::publish(const MqttMessage& message, int qos) | @@ -215,15 +222,15 @@ Token MqttClient::publish(const MqttMessage& message, int qos) | ||
| 215 | { | 222 | { |
| 216 | if( !m_principalClient ) | 223 | if( !m_principalClient ) |
| 217 | { | 224 | { |
| 218 | - std::cout << "Principal client not initialized" << std::endl; | 225 | + LogInfo( "[MqttClient::publish]", std::string( "Principal client not initialized") ); |
| 219 | } | 226 | } |
| 220 | 227 | ||
| 221 | if( m_principalClient->connectionStatus() == ConnectionStatus::Disconnected ) | 228 | if( m_principalClient->connectionStatus() == ConnectionStatus::Disconnected ) |
| 222 | { | 229 | { |
| 223 | std::cout << "Unable to publish, not connected.." << std::endl; | 230 | std::cout << "Unable to publish, not connected.." << std::endl; |
| 224 | } | 231 | } |
| 225 | - // ErrorLogToFIle ("MqttClient", "%1 - Unable to publish, not connected", m_clientId); | ||
| 226 | - // Throw (MqttException, "Not connected"); | 232 | + LogError("MqttClient", std::string( m_clientId + " - Unable to publish, not connected" ) ); |
| 233 | + | ||
| 227 | return Token(m_clientId, -1); | 234 | return Token(m_clientId, -1); |
| 228 | } | 235 | } |
| 229 | client = m_principalClient.get(); | 236 | client = m_principalClient.get(); |
| @@ -233,7 +240,7 @@ Token MqttClient::publish(const MqttMessage& message, int qos) | @@ -233,7 +240,7 @@ Token MqttClient::publish(const MqttMessage& message, int qos) | ||
| 233 | 240 | ||
| 234 | Token MqttClient::subscribe(const std::string& topic, int qos, const std::function<void(MqttMessage)>& cb) | 241 | Token MqttClient::subscribe(const std::string& topic, int qos, const std::function<void(MqttMessage)>& cb) |
| 235 | { | 242 | { |
| 236 | - // DebugLogToFIle ("MqttClient", "%1 - Subscribe to topic %2 with qos %3", m_clientId, topic, qos); | 243 | + LogDebug( "[MqttClient::subscribe]", std::string( m_clientId + " - Subscribe to topic " + topic ) ); |
| 237 | // OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); | 244 | // OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); |
| 238 | bool clientFound = false; | 245 | bool clientFound = false; |
| 239 | IMqttClientImpl* client(nullptr); | 246 | IMqttClientImpl* client(nullptr); |
| @@ -241,7 +248,7 @@ Token MqttClient::subscribe(const std::string& topic, int qos, const std::functi | @@ -241,7 +248,7 @@ Token MqttClient::subscribe(const std::string& topic, int qos, const std::functi | ||
| 241 | // OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); | 248 | // OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); |
| 242 | if (!m_principalClient || m_principalClient->connectionStatus() == ConnectionStatus::Disconnected) | 249 | if (!m_principalClient || m_principalClient->connectionStatus() == ConnectionStatus::Disconnected) |
| 243 | { | 250 | { |
| 244 | - // ErrorLogToFIle ("MqttClient", "%1 - Unable to subscribe, not connected", m_clientId); | 251 | + LogError("MqttClient", std::string( m_clientId + " - Unable to subscribe, not connected" ) ); |
| 245 | // throw (?)(MqttException, "Not connected"); | 252 | // throw (?)(MqttException, "Not connected"); |
| 246 | return Token(m_clientId, -1); | 253 | return Token(m_clientId, -1); |
| 247 | } | 254 | } |
| @@ -259,7 +266,7 @@ Token MqttClient::subscribe(const std::string& topic, int qos, const std::functi | @@ -259,7 +266,7 @@ Token MqttClient::subscribe(const std::string& topic, int qos, const std::functi | ||
| 259 | } | 266 | } |
| 260 | } | 267 | } |
| 261 | if (!clientFound) { | 268 | if (!clientFound) { |
| 262 | - // DebugLogToFIle ("MqttClient", "%1 - Creating new ClientPaho instance for subscription on topic %2", m_clientId, topic); | 269 | + LogDebug("[MqttClient::subscribe]", std::string( m_clientId + " - Creating new ClientPaho instance for subscription on topic " + topic ) ); |
| 263 | std::string derivedClientId(generateUniqueClientId(m_clientId, m_additionalClients.size() + 2)); // principal client is nr 1. | 270 | std::string derivedClientId(generateUniqueClientId(m_clientId, m_additionalClients.size() + 2)); // principal client is nr 1. |
| 264 | m_additionalClients.emplace_back(std::make_unique<ClientPaho>( | 271 | m_additionalClients.emplace_back(std::make_unique<ClientPaho>( |
| 265 | m_endpoint, | 272 | m_endpoint, |
| @@ -277,13 +284,13 @@ Token MqttClient::subscribe(const std::string& topic, int qos, const std::functi | @@ -277,13 +284,13 @@ Token MqttClient::subscribe(const std::string& topic, int qos, const std::functi | ||
| 277 | 284 | ||
| 278 | std::set<Token> MqttClient::unsubscribe(const std::string& topic, int qos) | 285 | std::set<Token> MqttClient::unsubscribe(const std::string& topic, int qos) |
| 279 | { | 286 | { |
| 280 | - // DebugLogToFIle ("MqttClient", "%1 - Unsubscribe from topic %2 with qos %3", m_clientId, topic, qos); | 287 | + LogDebug("[MqttClient::unsubscribe]", std::string( m_clientId + " - Unsubscribe from topic " + topic ) ); |
| 281 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); | 288 | OSDEV_COMPONENTS_LOCKGUARD(m_interfaceMutex); |
| 282 | std::vector<IMqttClientImpl*> clients{}; | 289 | std::vector<IMqttClientImpl*> clients{}; |
| 283 | { | 290 | { |
| 284 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); | 291 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); |
| 285 | if (!m_principalClient || m_principalClient->connectionStatus() == ConnectionStatus::Disconnected) { | 292 | if (!m_principalClient || m_principalClient->connectionStatus() == ConnectionStatus::Disconnected) { |
| 286 | - // ErrorLogToFIle ("MqttClient", "%1 - Unable to unsubscribe, not connected", m_clientId); | 293 | + LogError("[MqttClient::unsubscribe]", std::string( m_clientId + " - Unable to unsubscribe, not connected" ) ); |
| 287 | // Throw (MqttException, "Not connected"); | 294 | // Throw (MqttException, "Not connected"); |
| 288 | return std::set<Token>(); | 295 | return std::set<Token>(); |
| 289 | } | 296 | } |
| @@ -366,9 +373,7 @@ std::string MqttClient::endpoint() const | @@ -366,9 +373,7 @@ std::string MqttClient::endpoint() const | ||
| 366 | 373 | ||
| 367 | void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus cs) | 374 | void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus cs) |
| 368 | { | 375 | { |
| 369 | - (void)id; | ||
| 370 | - (void)cs; | ||
| 371 | - // DebugLogToFIle ("MqttClient", "%1 - connection status of wrapped client %2 changed to %3", m_clientId, id, cs); | 376 | + LogDebug("[MqttClient::connectionStatusChanged]", std::string( m_clientId + " - connection status of wrapped client " + id + " changed to " + std::to_string( static_cast<int>(cs) ) ) ); |
| 372 | IMqttClientImpl* principalClient{ nullptr }; | 377 | IMqttClientImpl* principalClient{ nullptr }; |
| 373 | std::vector<IMqttClientImpl*> clients{}; | 378 | std::vector<IMqttClientImpl*> clients{}; |
| 374 | std::vector<ConnectionStatus> connectionStates{}; | 379 | std::vector<ConnectionStatus> connectionStates{}; |
| @@ -399,7 +404,7 @@ void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus | @@ -399,7 +404,7 @@ void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus | ||
| 399 | cl->resubscribe(); | 404 | cl->resubscribe(); |
| 400 | } | 405 | } |
| 401 | catch (const std::exception& e) { | 406 | catch (const std::exception& e) { |
| 402 | - // ErrorLogToFIle ("MqttClient", "%1 - resubscribe on wrapped client %2 in context of connection status change in wrapped client %3 failed : %4", m_clientId, cl->clientId(), id, e.what()); | 407 | + LogError("[MqttClient::connectionStatusChanged]", std::string( m_clientId + " - resubscribe on wrapped client " + cl->clientId() + " in context of connection status change in wrapped client : " + id + " => FAILED : " + e.what() ) ); |
| 403 | } | 408 | } |
| 404 | } | 409 | } |
| 405 | m_activeTokensCV.notify_all(); | 410 | m_activeTokensCV.notify_all(); |
| @@ -414,7 +419,7 @@ void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus | @@ -414,7 +419,7 @@ void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus | ||
| 414 | auto waitFor = std::chrono::milliseconds(1000); | 419 | auto waitFor = std::chrono::milliseconds(1000); |
| 415 | if (!waitForCompletionInternalClients(clients, waitFor, std::set<Token>{})) { | 420 | if (!waitForCompletionInternalClients(clients, waitFor, std::set<Token>{})) { |
| 416 | if (std::accumulate(clients.begin(), clients.end(), false, [](bool hasPending, IMqttClientImpl* client) { return hasPending || client->hasPendingSubscriptions(); })) { | 421 | if (std::accumulate(clients.begin(), clients.end(), false, [](bool hasPending, IMqttClientImpl* client) { return hasPending || client->hasPendingSubscriptions(); })) { |
| 417 | - // WarnLogToFIle ("MqttClient", "%1 - subscriptions are not recovered within timeout.", m_clientId) | 422 | + LogWarning("[MqttClient::connectionStatusChanged]", std::string( m_clientId + " - subscriptions are not recovered within timeout." ) ); |
| 418 | } | 423 | } |
| 419 | } | 424 | } |
| 420 | if (principalClient) { | 425 | if (principalClient) { |
| @@ -422,7 +427,7 @@ void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus | @@ -422,7 +427,7 @@ void MqttClient::connectionStatusChanged(const std::string& id, ConnectionStatus | ||
| 422 | principalClient->publishPending(); | 427 | principalClient->publishPending(); |
| 423 | } | 428 | } |
| 424 | catch (const std::exception& e) { | 429 | catch (const std::exception& e) { |
| 425 | - // ErrorLogToFIle ("MqttClient", "%1 - publishPending on wrapped client %2 failed : %3", m_clientId, principalClient->clientId(), e.what()); | 430 | + LogError( "[MqttClient::connectionStatusChanged]", std::string( m_clientId + " - publishPending on wrapped client " + principalClient->clientId() + " => FAILED " + e.what() ) ); |
| 426 | } | 431 | } |
| 427 | } | 432 | } |
| 428 | } | 433 | } |
| @@ -441,7 +446,7 @@ void MqttClient::deliveryComplete(const std::string& _clientId, std::int32_t tok | @@ -441,7 +446,7 @@ void MqttClient::deliveryComplete(const std::string& _clientId, std::int32_t tok | ||
| 441 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); | 446 | OSDEV_COMPONENTS_LOCKGUARD(m_internalMutex); |
| 442 | if (!m_activeTokens.insert(t).second) { | 447 | if (!m_activeTokens.insert(t).second) { |
| 443 | // This should not happen. This means that some callback on the wrapper never came. | 448 | // This should not happen. This means that some callback on the wrapper never came. |
| 444 | - // ErrorLogToFIle ("MqttClient", "%1 -deliveryComplete, token %1 is already active", m_clientId, t); | 449 | + LogDebug("[MqttClient::deliveryComplete]", std::string( m_clientId + " - deliveryComplete, token is already active" ) ); |
| 445 | } | 450 | } |
| 446 | } | 451 | } |
| 447 | this->pushEvent([this, t]() { | 452 | this->pushEvent([this, t]() { |
| @@ -538,8 +543,9 @@ void MqttClient::pushEvent(std::function<void()> ev) | @@ -538,8 +543,9 @@ void MqttClient::pushEvent(std::function<void()> ev) | ||
| 538 | 543 | ||
| 539 | void MqttClient::eventHandler() | 544 | void MqttClient::eventHandler() |
| 540 | { | 545 | { |
| 541 | - // InfoLogToFIle ("MqttClient", "%1 - starting event handler", m_clientId); | ||
| 542 | - for (;;) { | 546 | + LogInfo("[MqttClient::eventHandler]", std::string( m_clientId + " - starting event handler." ) ); |
| 547 | + for (;;) | ||
| 548 | + { | ||
| 543 | std::vector<std::function<void()>> events; | 549 | std::vector<std::function<void()>> events; |
| 544 | if (!m_eventQueue.pop(events)) | 550 | if (!m_eventQueue.pop(events)) |
| 545 | { | 551 | { |
| @@ -550,5 +556,5 @@ void MqttClient::eventHandler() | @@ -550,5 +556,5 @@ void MqttClient::eventHandler() | ||
| 550 | ev(); | 556 | ev(); |
| 551 | } | 557 | } |
| 552 | } | 558 | } |
| 553 | - // InfoLogToFIle ("MqttClient", "%1 - leaving event handler", m_clientId); | 559 | + LogInfo("[MqttClient::eventHandler]", std::string( m_clientId + " - leaving event handler." ) ); |
| 554 | } | 560 | } |
test/CMakeLists.txt
| @@ -27,7 +27,7 @@ target_link_libraries( | @@ -27,7 +27,7 @@ target_link_libraries( | ||
| 27 | set_target_properties( ${PROJECT_NAME} PROPERTIES | 27 | set_target_properties( ${PROJECT_NAME} PROPERTIES |
| 28 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin | 28 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin |
| 29 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib | 29 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib |
| 30 | - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive | 30 | + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib |
| 31 | ) | 31 | ) |
| 32 | 32 | ||
| 33 | include(installation) | 33 | include(installation) |