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:
Thomas Basler
2025-04-09 19:36:46 +02:00
parent 1f3f275689
commit 542e755c64
6 changed files with 18 additions and 17 deletions

View File

@@ -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);
}
}
}

View File

@@ -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,
};
};
};