mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 23:45:49 +08:00
Rename MQTTPublisher to MQTTConnection.
This commit is contained in:
4
Log.cpp
4
Log.cpp
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "Log.h"
|
||||
#include "MQTTPublisher.h"
|
||||
#include "MQTTConnection.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <Windows.h>
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
CMQTTPublisher* m_mqtt = NULL;
|
||||
CMQTTConnection* m_mqtt = NULL;
|
||||
|
||||
static unsigned int m_mqttLevel = 2U;
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -101,7 +101,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -123,7 +123,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@@ -141,7 +141,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "MQTTPublisher.h"
|
||||
#include "MQTTConnection.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#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_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<CMQTTPublisher*>(obj);
|
||||
CMQTTConnection* p = static_cast<CMQTTConnection*>(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<CMQTTPublisher*>(obj);
|
||||
CMQTTConnection* p = static_cast<CMQTTConnection*>(obj);
|
||||
p->m_connected = false;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
8
Makefile
8
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 $@ $<
|
||||
|
||||
@@ -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 <cstring>
|
||||
#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),
|
||||
|
||||
Reference in New Issue
Block a user