From 8fafded304e8cbef1c21accd9ef33bd9b292e5b4 Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 15 Jan 2017 13:13:17 +0100 Subject: [PATCH] better readability --- src/ebusd/mqtthandler.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index d995fa39..521265e5 100644 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -196,11 +196,11 @@ MqttHandler::MqttHandler(BusHandler* busHandler, MessageMap* messages) } else { string clientId = PACKAGE_STRING; clientId += " "+static_cast(getpid()); - m_mosquitto = mosquitto_new(clientId.c_str(), #if (LIBMOSQUITTO_MAJOR >= 1) - true, + m_mosquitto = mosquitto_new(clientId.c_str(), true, this); +#else + m_mosquitto = mosquitto_new(clientId.c_str(), this); #endif - this); if (!m_mosquitto) { logOtherError("mqtt", "unable to instantiate"); } @@ -211,16 +211,19 @@ MqttHandler::MqttHandler(BusHandler* busHandler, MessageMap* messages) string willTopic = m_globalTopic+"running"; string willData = "false"; size_t len = willData.length(); - mosquitto_will_set(m_mosquitto, -#if (LIBMOSQUITTO_MAJOR < 1) - true, +#if (LIBMOSQUITTO_MAJOR >= 1) + mosquitto_will_set(m_mosquitto, willTopic.c_str(), (uint32_t)len, + reinterpret_cast(willData.c_str()), 0, true); +#else + mosquitto_will_set(m_mosquitto, true, willTopic.c_str(), (uint32_t)len, + reinterpret_cast(willData.c_str()), 0, true); #endif - willTopic.c_str(), (uint32_t)len, reinterpret_cast(willData.c_str()), 0, true); - if (mosquitto_connect(m_mosquitto, g_host, g_port, 60 -#if (LIBMOSQUITTO_MAJOR < 1) - , true + +#if (LIBMOSQUITTO_MAJOR >= 1) + if (mosquitto_connect(m_mosquitto, g_host, g_port, 60) != MOSQ_ERR_SUCCESS) { +#else + if (mosquitto_connect(m_mosquitto, g_host, g_port, 60, true) != MOSQ_ERR_SUCCESS) { #endif - ) != MOSQ_ERR_SUCCESS) { logOtherError("mqtt", "unable to connect"); mosquitto_destroy(m_mosquitto); m_mosquitto = NULL; @@ -408,11 +411,11 @@ void MqttHandler::run() { void MqttHandler::handleTraffic() { if (m_mosquitto) { - mosquitto_loop(m_mosquitto, -1 #if (LIBMOSQUITTO_MAJOR >= 1) - , 1 + mosquitto_loop(m_mosquitto, -1, 1); +#else + mosquitto_loop(m_mosquitto, -1); #endif - ); } }