mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2026-01-06 04:44:50 +01:00
Remove not required parameters from MqttSubscribeParser
index and total are only required to handle different payload fragments. This is not done here. In a further step, the correct fragment handling will be implemented outside this library.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright (C) 2022 Thomas Basler and others
|
||||
* Copyright (C) 2022-2025 Thomas Basler and others
|
||||
*/
|
||||
#include "MqttSubscribeParser.h"
|
||||
|
||||
void MqttSubscribeParser::register_callback(const std::string& topic, uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb)
|
||||
void MqttSubscribeParser::register_callback(const std::string& topic, uint8_t qos, const OnMessageCallback& cb)
|
||||
{
|
||||
cb_filter_t cbf;
|
||||
cbf.topic = topic;
|
||||
@@ -24,13 +24,13 @@ void MqttSubscribeParser::unregister_callback(const std::string& topic)
|
||||
}
|
||||
}
|
||||
|
||||
void MqttSubscribeParser::handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
||||
void MqttSubscribeParser::handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len)
|
||||
{
|
||||
bool result = false;
|
||||
for (const auto& cb : _callbacks) {
|
||||
if (mosquitto_topic_matches_sub(cb.topic.c_str(), topic, &result) == MOSQ_ERR_SUCCESS) {
|
||||
if (result) {
|
||||
cb.cb(properties, topic, payload, len, index, total);
|
||||
cb.cb(properties, topic, payload, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,19 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef std::function<void(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len)> OnMessageCallback;
|
||||
|
||||
struct cb_filter_t {
|
||||
std::string topic;
|
||||
uint8_t qos;
|
||||
espMqttClientTypes::OnMessageCallback cb;
|
||||
OnMessageCallback cb;
|
||||
};
|
||||
|
||||
class MqttSubscribeParser {
|
||||
public:
|
||||
void register_callback(const std::string& topic, uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb);
|
||||
void register_callback(const std::string& topic, uint8_t qos, const OnMessageCallback& cb);
|
||||
void unregister_callback(const std::string& topic);
|
||||
void handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
||||
void handle_message(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len);
|
||||
std::vector<cb_filter_t> get_callbacks();
|
||||
|
||||
private:
|
||||
@@ -28,4 +30,4 @@ private:
|
||||
MOSQ_ERR_SUCCESS = 0,
|
||||
MOSQ_ERR_INVAL = 3,
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user