mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-11 17:30:37 +01:00
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.
34 lines
994 B
C++
34 lines
994 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <espMqttClient.h>
|
|
#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;
|
|
OnMessageCallback cb;
|
|
};
|
|
|
|
class MqttSubscribeParser {
|
|
public:
|
|
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);
|
|
std::vector<cb_filter_t> get_callbacks();
|
|
|
|
private:
|
|
int mosquitto_topic_matches_sub(const char* sub, const char* topic, bool* result);
|
|
|
|
std::vector<cb_filter_t> _callbacks;
|
|
|
|
enum mosq_err_t {
|
|
MOSQ_ERR_SUCCESS = 0,
|
|
MOSQ_ERR_INVAL = 3,
|
|
};
|
|
};
|