Rename MQTTPublisher to MQTTConnection.

This commit is contained in:
Jonathan Naylor
2023-06-19 14:57:30 +01:00
parent cf9d470f23
commit ff004211b9
7 changed files with 27 additions and 33 deletions

View File

@@ -17,7 +17,7 @@
*/ */
#include "Log.h" #include "Log.h"
#include "MQTTPublisher.h" #include "MQTTConnection.h"
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#include <Windows.h> #include <Windows.h>
@@ -33,7 +33,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
CMQTTPublisher* m_mqtt = NULL; CMQTTConnection* m_mqtt = NULL;
static unsigned int m_mqttLevel = 2U; static unsigned int m_mqttLevel = 2U;

View File

@@ -26,7 +26,7 @@
#include "I2CController.h" #include "I2CController.h"
#endif #endif
#include "UDPController.h" #include "UDPController.h"
#include "MQTTPublisher.h" #include "MQTTConnection.h"
#include "DStarDefines.h" #include "DStarDefines.h"
#include "Version.h" #include "Version.h"
#include "StopWatch.h" #include "StopWatch.h"
@@ -62,7 +62,7 @@ static int m_signal = 0;
static bool m_reload = false; static bool m_reload = false;
// In Log.cpp // In Log.cpp
extern CMQTTPublisher* m_mqtt; extern CMQTTConnection* m_mqtt;
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
static void sigHandler1(int signum) static void sigHandler1(int signum)
@@ -289,7 +289,7 @@ int CMMDVMHost::run()
return 1; 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(); ret = m_mqtt->open();
if (!ret) { if (!ret) {
::fprintf(stderr, "MMDVMHost: unable to start the MQTT Publisher\n"); ::fprintf(stderr, "MMDVMHost: unable to start the MQTT Publisher\n");

View File

@@ -87,7 +87,7 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@@ -101,7 +101,7 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_LOG_H;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@@ -123,7 +123,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@@ -141,7 +141,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_LOG_H;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

View File

@@ -16,14 +16,14 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "MQTTPublisher.h" #include "MQTTConnection.h"
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
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_host(host),
m_port(port), m_port(port),
m_name(name), m_name(name),
@@ -40,12 +40,12 @@ m_connected(false)
::mosquitto_lib_init(); ::mosquitto_lib_init();
} }
CMQTTPublisher::~CMQTTPublisher() CMQTTConnection::~CMQTTConnection()
{ {
::mosquitto_lib_cleanup(); ::mosquitto_lib_cleanup();
} }
bool CMQTTPublisher::open() bool CMQTTConnection::open()
{ {
m_mosq = ::mosquitto_new(m_name.c_str(), true, this); m_mosq = ::mosquitto_new(m_name.c_str(), true, this);
if (m_mosq == NULL){ if (m_mosq == NULL){
@@ -76,7 +76,7 @@ bool CMQTTPublisher::open()
return true; return true;
} }
bool CMQTTPublisher::publish(const char* topic, const char* text) bool CMQTTConnection::publish(const char* topic, const char* text)
{ {
assert(topic != NULL); assert(topic != NULL);
assert(text != NULL); assert(text != NULL);
@@ -96,7 +96,7 @@ bool CMQTTPublisher::publish(const char* topic, const char* text)
return true; return true;
} }
void CMQTTPublisher::close() void CMQTTConnection::close()
{ {
if (m_mosq != NULL) { if (m_mosq != NULL) {
::mosquitto_disconnect(m_mosq); ::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(mosq != NULL);
assert(obj != NULL); assert(obj != NULL);
::fprintf(stdout, "MQTT: on_connect: %s\n", ::mosquitto_connack_string(rc)); ::fprintf(stdout, "MQTT: on_connect: %s\n", ::mosquitto_connack_string(rc));
CMQTTPublisher* p = static_cast<CMQTTPublisher*>(obj); CMQTTConnection* p = static_cast<CMQTTConnection*>(obj);
p->m_connected = true; 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(mosq != NULL);
assert(obj != NULL); assert(obj != NULL);
::fprintf(stdout, "MQTT: on_disconnect: %s\n", ::mosquitto_reason_string(rc)); ::fprintf(stdout, "MQTT: on_disconnect: %s\n", ::mosquitto_reason_string(rc));
CMQTTPublisher* p = static_cast<CMQTTPublisher*>(obj); CMQTTConnection* p = static_cast<CMQTTConnection*>(obj);
p->m_connected = false; p->m_connected = false;
} }

View File

@@ -29,10 +29,10 @@ enum MQTT_QOS {
MQTT_QOS_EXACTLY_ONCE = 2U MQTT_QOS_EXACTLY_ONCE = 2U
}; };
class CMQTTPublisher { class CMQTTConnection {
public: public:
CMQTTPublisher(const std::string& host, unsigned short port, const std::string& name, unsigned int keepalive, MQTT_QOS qos = MQTT_QOS_EXACTLY_ONCE); CMQTTConnection(const std::string& host, unsigned short port, const std::string& name, unsigned int keepalive, MQTT_QOS qos = MQTT_QOS_EXACTLY_ONCE);
~CMQTTPublisher(); ~CMQTTConnection();
bool open(); bool open();

View File

@@ -2,7 +2,7 @@
CC = cc CC = cc
CXX = c++ 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 LIBS = -lpthread -lutil -lmosquitto
LDFLAGS = -g -L/usr/local/lib 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 \ 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 \ 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 \ 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 \ 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 \ 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 \ 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) MMDVMHost: GitVersion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost $(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
RemoteCommand: Log.o MQTTPublisher.o RemoteCommand.o UDPSocket.o RemoteCommand: Log.o MQTTConnection.o RemoteCommand.o UDPSocket.o
$(CXX) Log.o MQTTPublisher.o RemoteCommand.o UDPSocket.o $(CFLAGS) $(LIBS) -o RemoteCommand $(CXX) Log.o MQTTConnection.o RemoteCommand.o UDPSocket.o $(CFLAGS) $(LIBS) -o RemoteCommand
%.o: %.cpp %.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $< $(CXX) $(CFLAGS) -c -o $@ $<

View File

@@ -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 * 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 * it under the terms of the GNU General Public License as published by
@@ -25,13 +25,7 @@
#include <cstring> #include <cstring>
#endif #endif
#if defined(HAVE_LOG_H)
#include "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) : CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_address_save(address), m_address_save(address),