diff --git a/Log.cpp b/Log.cpp index b4dacc3..b6a5d47 100644 --- a/Log.cpp +++ b/Log.cpp @@ -17,7 +17,7 @@ */ #include "Log.h" -#include "MQTTPublisher.h" +#include "MQTTConnection.h" #if defined(_WIN32) || defined(_WIN64) #include @@ -33,7 +33,7 @@ #include #include -CMQTTPublisher* m_mqtt = NULL; +CMQTTConnection* m_mqtt = NULL; static unsigned int m_mqttLevel = 2U; diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 2e8efdb..b33f8a8 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -26,7 +26,7 @@ #include "I2CController.h" #endif #include "UDPController.h" -#include "MQTTPublisher.h" +#include "MQTTConnection.h" #include "DStarDefines.h" #include "Version.h" #include "StopWatch.h" @@ -62,7 +62,7 @@ static int m_signal = 0; static bool m_reload = false; // In Log.cpp -extern CMQTTPublisher* m_mqtt; +extern CMQTTConnection* m_mqtt; #if !defined(_WIN32) && !defined(_WIN64) static void sigHandler1(int signum) @@ -289,7 +289,7 @@ int CMMDVMHost::run() return 1; } - m_mqtt = new CMQTTPublisher(m_conf.getMQTTHost(), m_conf.getMQTTPort(), m_conf.getMQTTName(), m_conf.getMQTTKeepalive()); + m_mqtt = new CMQTTConnection(m_conf.getMQTTHost(), m_conf.getMQTTPort(), m_conf.getMQTTName(), m_conf.getMQTTKeepalive()); ret = m_mqtt->open(); if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to start the MQTT Publisher\n"); diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index 41835c9..456c4a0 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -87,7 +87,7 @@ Level3 Disabled - HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Console @@ -101,7 +101,7 @@ Level3 Disabled - HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Console @@ -123,7 +123,7 @@ MaxSpeed true true - HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Console @@ -141,7 +141,7 @@ MaxSpeed true true - HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Console diff --git a/MQTTPublisher.cpp b/MQTTConnection.cpp similarity index 82% rename from MQTTPublisher.cpp rename to MQTTConnection.cpp index d3bb48c..a149615 100644 --- a/MQTTPublisher.cpp +++ b/MQTTConnection.cpp @@ -16,14 +16,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "MQTTPublisher.h" +#include "MQTTConnection.h" #include #include #include -CMQTTPublisher::CMQTTPublisher(const std::string& host, unsigned short port, const std::string& name, unsigned int keepalive, MQTT_QOS qos) : +CMQTTConnection::CMQTTConnection(const std::string& host, unsigned short port, const std::string& name, unsigned int keepalive, MQTT_QOS qos) : m_host(host), m_port(port), m_name(name), @@ -40,12 +40,12 @@ m_connected(false) ::mosquitto_lib_init(); } -CMQTTPublisher::~CMQTTPublisher() +CMQTTConnection::~CMQTTConnection() { ::mosquitto_lib_cleanup(); } -bool CMQTTPublisher::open() +bool CMQTTConnection::open() { m_mosq = ::mosquitto_new(m_name.c_str(), true, this); if (m_mosq == NULL){ @@ -76,7 +76,7 @@ bool CMQTTPublisher::open() return true; } -bool CMQTTPublisher::publish(const char* topic, const char* text) +bool CMQTTConnection::publish(const char* topic, const char* text) { assert(topic != NULL); assert(text != NULL); @@ -96,7 +96,7 @@ bool CMQTTPublisher::publish(const char* topic, const char* text) return true; } -void CMQTTPublisher::close() +void CMQTTConnection::close() { if (m_mosq != NULL) { ::mosquitto_disconnect(m_mosq); @@ -105,25 +105,25 @@ void CMQTTPublisher::close() } } -void CMQTTPublisher::onConnect(mosquitto* mosq, void* obj, int rc) +void CMQTTConnection::onConnect(mosquitto* mosq, void* obj, int rc) { assert(mosq != NULL); assert(obj != NULL); ::fprintf(stdout, "MQTT: on_connect: %s\n", ::mosquitto_connack_string(rc)); - CMQTTPublisher* p = static_cast(obj); + CMQTTConnection* p = static_cast(obj); p->m_connected = true; } -void CMQTTPublisher::onDisconnect(mosquitto* mosq, void* obj, int rc) +void CMQTTConnection::onDisconnect(mosquitto* mosq, void* obj, int rc) { assert(mosq != NULL); assert(obj != NULL); ::fprintf(stdout, "MQTT: on_disconnect: %s\n", ::mosquitto_reason_string(rc)); - CMQTTPublisher* p = static_cast(obj); + CMQTTConnection* p = static_cast(obj); p->m_connected = false; } diff --git a/MQTTPublisher.h b/MQTTConnection.h similarity index 87% rename from MQTTPublisher.h rename to MQTTConnection.h index 74ad233..2a0adfe 100644 --- a/MQTTPublisher.h +++ b/MQTTConnection.h @@ -29,10 +29,10 @@ enum MQTT_QOS { MQTT_QOS_EXACTLY_ONCE = 2U }; -class CMQTTPublisher { +class CMQTTConnection { public: - CMQTTPublisher(const std::string& host, unsigned short port, const std::string& name, unsigned int keepalive, MQTT_QOS qos = MQTT_QOS_EXACTLY_ONCE); - ~CMQTTPublisher(); + CMQTTConnection(const std::string& host, unsigned short port, const std::string& name, unsigned int keepalive, MQTT_QOS qos = MQTT_QOS_EXACTLY_ONCE); + ~CMQTTConnection(); bool open(); diff --git a/Makefile b/Makefile index bc50df0..622e0ef 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC = cc CXX = c++ -CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -I/usr/local/include +CFLAGS = -g -O3 -Wall -std=c++0x -pthread -I/usr/local/include LIBS = -lpthread -lutil -lmosquitto LDFLAGS = -g -L/usr/local/lib @@ -11,7 +11,7 @@ OBJECTS = \ DMREMB.o DMREmbeddedData.o DMRFullLC.o DMRLookup.o DMRLC.o DMRNetwork.o DMRShortLC.o DMRSlot.o DMRSlotType.o \ DMRAccessControl.o DMRTA.o DMRTrellis.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o FMControl.o FMNetwork.o Golay2087.o Golay24128.o \ Hamming.o I2CController.o IIRDirectForm1Filter.o Log.o M17Control.o M17Convolution.o M17CRC.o M17LSF.o M17Network.o M17Utils.o MMDVMHost.o \ - MQTTPublisher.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NullController.o NXDNAudio.o NXDNControl.o \ + MQTTConnection.o Modem.o ModemPort.o ModemSerialPort.o Mutex.o NullController.o NXDNAudio.o NXDNControl.o \ NXDNConvolution.o NXDNCRC.o NXDNFACCH1.o NXDNIcomNetwork.o NXDNKenwoodNetwork.o NXDNLayer3.o NXDNLICH.o NXDNLookup.o NXDNNetwork.o NXDNSACCH.o \ NXDNUDCH.o P25Audio.o P25Control.o P25Data.o P25LowSpeedData.o P25Network.o P25NID.o P25Trellis.o P25Utils.o PseudoTTYController.o POCSAGControl.o \ POCSAGNetwork.o QR1676.o RemoteControl.o RS129.o RS241213.o RSSIInterpolator.o SerialPort.o StopWatch.o Sync.o SHA256.o Thread.o \ @@ -22,8 +22,8 @@ all: MMDVMHost RemoteCommand MMDVMHost: GitVersion.h $(OBJECTS) $(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost -RemoteCommand: Log.o MQTTPublisher.o RemoteCommand.o UDPSocket.o - $(CXX) Log.o MQTTPublisher.o RemoteCommand.o UDPSocket.o $(CFLAGS) $(LIBS) -o RemoteCommand +RemoteCommand: Log.o MQTTConnection.o RemoteCommand.o UDPSocket.o + $(CXX) Log.o MQTTConnection.o RemoteCommand.o UDPSocket.o $(CFLAGS) $(LIBS) -o RemoteCommand %.o: %.cpp $(CXX) $(CFLAGS) -c -o $@ $< diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 0792863..4ebfa85 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2016,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2006-2016,2020,2023 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,13 +25,7 @@ #include #endif -#if defined(HAVE_LOG_H) #include "Log.h" -#else -#define LogMessage(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) -#define LogError(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) -#define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__) -#endif CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) : m_address_save(address),