MQTTSuite
Loading...
Searching...
No Matches
ConfigSections.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, 2026
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 CONFIG_SECTIONS
43#define CONFIG_SECTIONS
44
45#include <net/config/ConfigSection.h>
46
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
48
49#include <cstdint>
50#include <list>
51#include <string_view>
52
53#endif
54
55namespace mqtt::mqttcli::lib {
56
57 class ConfigSubscribe : public utils::SubCommand {
58 public:
59 constexpr static std::string_view NAME{"sub"};
60 constexpr static std::string_view DESCRIPTION{"Configuration for application mqttsub"};
61
62 ConfigSubscribe(utils::SubCommand* parent);
63
64 ~ConfigSubscribe() override;
65
66 std::list<std::string> getTopic() const;
67
68 const ConfigSubscribe& setTopic(const std::string& topic);
69
70 private:
71 CLI::Option* topicOpt;
72 };
73
74 class ConfigPublish : public utils::SubCommand {
75 public:
76 constexpr static std::string_view NAME{"pub"};
77 constexpr static std::string_view DESCRIPTION{"Configuration for application mqttpub"};
78
79 ConfigPublish(utils::SubCommand* parent);
80
81 ~ConfigPublish() override;
82
83 std::string getTopic() const;
84 const ConfigPublish& setTopic(const std::string& topic);
85
86 std::string getMessage() const;
87 const ConfigPublish& setMessage(const std::string& message);
88
89 bool getRetain() const;
90 const ConfigPublish& setRetain(bool retain);
91
92 private:
93 CLI::Option* topicOpt;
94 CLI::Option* messageOpt;
95 CLI::Option* retainOpt;
96 };
97
98 class ConfigSession : public utils::SubCommand {
99 public:
100 constexpr static std::string_view NAME{"session"};
101 constexpr static std::string_view DESCRIPTION{"MQTT session behavior"};
102
103 ConfigSession(utils::SubCommand* parent);
104
105 ~ConfigSession() override;
106
107 std::string getClientId() const;
108
109 const ConfigSession& setClientId(const std::string& clientId) const;
110
111 uint8_t getQoS() const;
112
113 const ConfigSession& setQos(uint8_t qoS) const;
114
115 bool getRetainSession() const;
116
117 const ConfigSession& setRetainSession(bool retainSession) const;
118
119 uint16_t getKeepAlive() const;
120
121 const ConfigSession& setKeepAlive(uint16_t keepAlive) const;
122
123 std::string getWillTopic() const;
124
125 const ConfigSession& setWillTopic(const std::string& willTopic) const;
126
127 std::string getWillMessage() const;
128
129 const ConfigSession& setWillMessage(const std::string& willMessage) const;
130
131 uint8_t getWillQoS() const;
132
133 const ConfigSession& settWillQoS(uint8_t willQoS) const;
134
135 bool getWillRetain() const;
136
137 const ConfigSession& setWillRetain(bool willRetain) const;
138
139 std::string getUsername() const;
140
141 const ConfigSession& settUsername(const std::string& username) const;
142
143 std::string getPassword() const;
144
145 const ConfigSession& setPassword(const std::string& password) const;
146
147 private:
148 CLI::Option* clientIdOpt;
149 CLI::Option* qoSOpt;
150 CLI::Option* retainSessionOpt;
151 CLI::Option* keepAliveOpt;
152 CLI::Option* willTopicOpt;
153 CLI::Option* willMessageOpt;
154 CLI::Option* willQoSOpt;
155 CLI::Option* willRetainOpt;
156 CLI::Option* usernameOpt;
157 CLI::Option* passwordOpt;
158 };
159
160} // namespace mqtt::mqttcli::lib
161
162#endif // CONFIG_SECTIONS
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
ConfigPublish(utils::SubCommand *parent)
static constexpr std::string_view DESCRIPTION
static constexpr std::string_view NAME
const ConfigPublish & setRetain(bool retain)
static constexpr std::string_view NAME
const ConfigSession & setKeepAlive(uint16_t keepAlive) const
const ConfigSession & setWillRetain(bool willRetain) const
ConfigSession(utils::SubCommand *parent)
const ConfigSession & setQos(uint8_t qoS) const
static constexpr std::string_view DESCRIPTION
const ConfigSession & setRetainSession(bool retainSession) const
const ConfigSession & settWillQoS(uint8_t willQoS) const
ConfigSubscribe(utils::SubCommand *parent)
std::list< std::string > getTopic() const
static constexpr std::string_view DESCRIPTION
static constexpr std::string_view NAME
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:217