mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-26 08:13:06 +05:00
refactor: use unique_ptr for the MQTT client
This commit is contained in:
1 parent
72a8cd0eb1
commit
aeac5bf726
1 file changed
+3
-4
+3
-4
@@ -20,7 +20,7 @@
|
||||
|
||||
std::mutex mqttMutex;
|
||||
|
||||
static MQTT* mqttClient = nullptr;
|
||||
static std::unique_ptr<MQTT> mqttClient;
|
||||
|
||||
// Keep the applied prefix separate from settings until MQTT is reconfigured.
|
||||
static std::string mqttPrefix; // NOLINT(runtime/string)
|
||||
@@ -534,8 +534,7 @@ void stopMqtt(bool destroy = false) {
|
||||
}
|
||||
|
||||
haDiscovery.reset();
|
||||
delete mqttClient;
|
||||
mqttClient = nullptr;
|
||||
mqttClient.reset();
|
||||
|
||||
std::string().swap(mqttPrefix);
|
||||
}
|
||||
@@ -682,7 +681,7 @@ static void connect() {
|
||||
if (!mqttClient) {
|
||||
std::lock_guard<std::mutex> lock(mqttMutex);
|
||||
|
||||
mqttClient = new MQTT();
|
||||
mqttClient = std::make_unique<MQTT>();
|
||||
mqttClient->setAsync(true);
|
||||
mqttClient->setConfigHook([](esp_mqtt_client_config_t& config) {
|
||||
config.session.last_will.qos = 1;
|
||||
|
||||
Reference in new issue
Block a user