MQTTSuite
Loading...
Searching...
No Matches
Mqtt.h
Go to the documentation of this file.
1/*
2 * MQTTSuite - A lightweight MQTT Integration System
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef APPS_MQTTBROKER_MQTT_SOCKETCONTEXT_H
43#define APPS_MQTTBROKER_MQTT_SOCKETCONTEXT_H
44
45#include <iot/mqtt/client/Mqtt.h>
46
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
48
49#include <cstdint>
50#include <list>
51#include <string>
52
53#endif
54
55namespace mqtt::mqttcli::lib {
56
57 class Mqtt : public iot::mqtt::client::Mqtt {
58 public:
59 explicit Mqtt(const std::string& connectionName,
60 const std::string& clientId,
61 uint8_t qoSDefault,
62 uint16_t keepAlive,
63 bool cleanSession,
64 const std::string& willTopic,
65 const std::string& willMessage,
66 uint8_t willQoS,
67 bool willRetain,
68 const std::string& username,
69 const std::string& password,
70 const std::list<std::string>& subTopics,
71 const std::string& pubTopic,
72 const std::string& pubMessage,
73 bool pubRetain = false,
74 const std::string& sessionStoreFileName = "");
75
76 private:
77 using Super = iot::mqtt::client::Mqtt;
78
79 void onConnected() final;
80 [[nodiscard]] bool onSignal(int signum) final;
81
82 void onPublish(const iot::mqtt::packets::Publish& publish) final;
83 void onConnack(const iot::mqtt::packets::Connack& connack) final;
84 void onSuback(const iot::mqtt::packets::Suback& suback) final;
85 void onPuback(const iot::mqtt::packets::Puback& puback) final;
86 void onPubcomp(const iot::mqtt::packets::Pubcomp& pubcomp) final;
87
88 const uint8_t qoSDefault;
89 const bool cleanSession;
90
91 const std::string willTopic;
92 const std::string willMessage;
93 const uint8_t willQoS;
94 const bool willRetain;
95 const std::string username;
96 const std::string password;
97
98 const std::list<std::string> subTopics;
99 const std::string pubTopic;
100 const std::string pubMessage;
101 const bool pubRetain;
102 };
103
104} // namespace mqtt::mqttcli::lib
105
106#endif // APPS_MQTTBROKER_MQTTSUB_SOCKETCONTEXT_H
nlohmann::json json
const std::string willTopic
Definition Mqtt.h:91
bool onSignal(int signum) final
Definition Mqtt.cpp:266
const uint8_t qoSDefault
Definition Mqtt.h:88
const bool willRetain
Definition Mqtt.h:94
void onConnack(const iot::mqtt::packets::Connack &connack) final
Definition Mqtt.cpp:285
void onConnected() final
Definition Mqtt.cpp:260
const std::string username
Definition Mqtt.h:95
const uint8_t willQoS
Definition Mqtt.h:93
iot::mqtt::client::Mqtt Super
Definition Mqtt.h:77
const std::string password
Definition Mqtt.h:96
const std::list< std::string > subTopics
Definition Mqtt.h:98
void onPublish(const iot::mqtt::packets::Publish &publish) final
Definition Mqtt.cpp:365
Mqtt(const std::string &connectionName, const std::string &clientId, uint8_t qoSDefault, uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, const std::list< std::string > &subTopics, const std::string &pubTopic, const std::string &pubMessage, bool pubRetain=false, const std::string &sessionStoreFileName="")
Definition Mqtt.cpp:220
const bool cleanSession
Definition Mqtt.h:89
const std::string pubMessage
Definition Mqtt.h:100
void onSuback(const iot::mqtt::packets::Suback &suback) final
Definition Mqtt.cpp:357
void onPuback(const iot::mqtt::packets::Puback &puback) final
Definition Mqtt.cpp:374
const bool pubRetain
Definition Mqtt.h:101
void onPubcomp(const iot::mqtt::packets::Pubcomp &pubcomp) final
Definition Mqtt.cpp:380
const std::string pubTopic
Definition Mqtt.h:99
const std::string willMessage
Definition Mqtt.h:92
static std::vector< std::string > myformat(const std::string &prefix, const std::string &headLine, const std::string &message, std::size_t initialPrefixLength=0)
Definition Mqtt.cpp:122
static const std::string formatAsLogString(const std::string &prefix, const std::string &headLine, const std::string &message)
Definition Mqtt.cpp:204
static int getTerminalWidth()
Definition Mqtt.cpp:76
static std::vector< std::string > wrapParagraph(const std::string &text, std::size_t width)
Definition Mqtt.cpp:88
static uint8_t getQos(const std::string &qoSString)
Definition Mqtt.cpp:275