Uniot Core
0.8.1
Loading...
Searching...
No Matches
CallbackMQTTDevice.h
Go to the documentation of this file.
1/*
2 * This is a part of the Uniot project.
3 * Copyright (C) 2016-2020 Uniot <contact@uniot.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <functional>
22#include <MQTTDevice.h>
23#include <Logger.h>
24
25namespace uniot
26{
27
39{
40public:
48 using Handler = std::function<void(MQTTDevice *device, const String &topic, const Bytes &payload)>;
49
56 : MQTTDevice(),
57 mHandler(handler)
58 {
59 }
60
61protected:
71 void handle(const String &topic, const Bytes &payload) override
72 {
73 UNIOT_LOG_DEBUG("topic: %s", topic.c_str());
74 mHandler(this, topic, payload);
75 }
76
81};
82
83} // namespace uniot
Definition Bytes.h:38
CallbackMQTTDevice(Handler handler)
Constructs a CallbackMQTTDevice with the specified message handler.
Definition CallbackMQTTDevice.h:55
std::function< void(MQTTDevice *device, const String &topic, const Bytes &payload)> Handler
Function type for MQTT message handlers.
Definition CallbackMQTTDevice.h:48
Handler mHandler
The user-provided message handler function.
Definition CallbackMQTTDevice.h:80
void handle(const String &topic, const Bytes &payload) override
Handles incoming MQTT messages by delegating to the callback function.
Definition CallbackMQTTDevice.h:71
MQTTDevice()
Constructs a new MQTTDevice instance.
Definition MQTTDevice.h:44
#define UNIOT_LOG_DEBUG(...)
Log an DEBUG level message Used for general information about system operation. Only compiled if UNIO...
Definition Logger.h:293
Contains all classes and functions related to the Uniot Core.