SNode.C
Loading...
Searching...
No Matches
ControlPacket.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef IOT_MQTT_CONTROLPACKET_H
21#define IOT_MQTT_CONTROLPACKET_H
22
23#ifndef DOXYGEN_SHOULD_SKIP_THIS
24
25#include <cstdint>
26#include <string>
27#include <vector>
28
29#endif // DOXYGEN_SHOULD_SKIP_THIS
30
31#define MQTT_RESERVED_00 0x00
32#define MQTT_CONNECT 0x01
33#define MQTT_CONNACK 0x02
34#define MQTT_PUBLISH 0x03
35#define MQTT_PUBACK 0x04
36#define MQTT_PUBREC 0x05
37#define MQTT_PUBREL 0x06
38#define MQTT_PUBCOMP 0x07
39#define MQTT_SUBSCRIBE 0x08
40#define MQTT_SUBACK 0x09
41#define MQTT_UNSUBSCRIBE 0x0A
42#define MQTT_UNSUBACK 0x0B
43#define MQTT_PINGREQ 0x0C
44#define MQTT_PINGRESP 0x0D
45#define MQTT_DISCONNECT 0x0E
46#define MQTT_RESERVED_0F 0x0F
47
48// no flags for MQTT_RESERVED_00
49#define MQTT_CONNECT_FLAGS 0x00
50#define MQTT_CONNACK_FLAGS 0x00
51// no flags for MQTT_PUBLISH_FLAGS
52#define MQTT_PUBACK_FLAGS 0x00
53#define MQTT_PUBREC_FLAGS 0x00
54#define MQTT_PUBREL_FLAGS 0x02
55#define MQTT_PUBCOMP_FLAGS 0x00
56#define MQTT_SUBSCRIBE_FLAGS 0x02
57#define MQTT_SUBACK_FLAGS 0x00
58#define MQTT_UNSUBSCRIBE_FLAGS 0x02
59#define MQTT_UNSUBACK_FLAGS 0x00
60#define MQTT_PINGREQ_FLAGS 0x00
61#define MQTT_PINGRESP_FLAGS 0x00
62#define MQTT_DISCONNECT_FLAGS 0x00
63// no flags for MQTT_RESERVED_0F
64
65namespace iot::mqtt {
66
67 extern const std::vector<std::string> mqttPackageName;
68
69 class ControlPacket {
70 public:
71 ControlPacket(uint8_t type, const std::string& name);
72 ControlPacket(const ControlPacket&) = default;
73 ControlPacket(ControlPacket&&) = default;
74
75 virtual ~ControlPacket();
76
77 ControlPacket& operator=(const ControlPacket&) = default;
78 ControlPacket& operator=(ControlPacket&&) = default;
79
80 virtual std::vector<char> serializeVP() const = 0;
81 std::vector<char> serialize() const;
82
83 const std::string& getName() const;
84 uint8_t getType() const;
85 uint8_t getFlags() const;
86
87 private:
88 std::string name;
89 uint8_t type = 0;
90
91 protected:
92 uint8_t flags = 0;
93 };
94
95} // namespace iot::mqtt
96
97#endif // IOT_MQTT_CONTROLPACKET_H
#define SUBSCRIBTION_MAX_QOS
Definition Broker.h:40
Session & operator=(const Session &)=default
std::set< uint16_t > publishPacketIdentifierSet
Definition Session.h:63
virtual nlohmann::json toJson() const
Definition Session.cpp:37
Session(const nlohmann::json &json)
Definition Session.cpp:33
bool isCleanSession() const
Session(const Session &)=default
virtual ~Session()=default
void fromJson(const nlohmann::json &json)
Definition Session.cpp:67
std::set< uint16_t > pubrelPacketIdentifierSet
Definition Session.h:60
virtual core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection, std::shared_ptr< iot::mqtt::server::broker::Broker > broker)=0
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
void restartSession(const std::string &clientId)
Definition Broker.cpp:187
uint8_t subscribe(const std::string &clientId, const std::string &topic, uint8_t qoS)
Definition Broker.cpp:142
bool hasActiveSession(const std::string &clientId)
Definition Broker.cpp:165
static std::shared_ptr< Broker > instance(uint8_t maxQoS)
Definition Broker.cpp:119
bool isActiveSession(const std::string &clientId, const Mqtt *mqtt)
Definition Broker.cpp:173
iot::mqtt::server::broker::RetainTree retainTree
Definition Broker.h:81
void publish(const std::string &originClientId, const std::string &topic, const std::string &message, uint8_t qoS, bool retain)
Definition Broker.cpp:134
bool hasSession(const std::string &clientId)
Definition Broker.cpp:161
void appear(const std::string &clientId, const std::string &topic, uint8_t qoS)
Definition Broker.cpp:125
void unsubscribe(const std::string &clientId, const std::string &topic)
Definition Broker.cpp:157
Session * renewSession(const std::string &clientId, iot::mqtt::server::Mqtt *mqtt)
Definition Broker.cpp:183
void deleteSession(const std::string &clientId)
Definition Broker.cpp:199
void unsubscribe(const std::string &clientId)
Definition Broker.cpp:129
bool hasRetainedSession(const std::string &clientId)
Definition Broker.cpp:169
iot::mqtt::server::broker::SubscribtionTree subscribtionTree
Definition Broker.h:80
Session * newSession(const std::string &clientId, iot::mqtt::server::Mqtt *mqtt)
Definition Broker.cpp:177
void sendPublish(const std::string &clientId, Message &message, uint8_t qoS, bool retain)
Definition Broker.cpp:204
void retainSession(const std::string &clientId)
Definition Broker.cpp:195
void setMessage(const std::string &message)
Definition Message.cpp:56
const std::string & getOriginClientId() const
Definition Message.cpp:40
nlohmann::json toJson() const
Definition Message.cpp:72
const std::string & getTopic() const
Definition Message.cpp:44
void setTopic(const std::string &topic)
Definition Message.cpp:48
const std::string & getMessage() const
Definition Message.cpp:52
Message & operator=(const Message &)=default
Message(const Message &message)=default
Message(const std::string &originClientId, const std::string &topic, const std::string &message, uint8_t qoS, bool originRetain)
Definition Message.cpp:31
Message & fromJson(const nlohmann::json &json)
Definition Message.cpp:83
void retain(const Message &message, std::string topic)
void appear(const std::string &clientId, uint8_t clientQoS)
TopicLevel(iot::mqtt::server::broker::Broker *broker)
TopicLevel & fromJson(const nlohmann::json &json)
void appear(const std::string &clientId, std::string topic, uint8_t qoS)
void appear(const std::string &clientId, const std::string &topic, uint8_t qoS)
void fromJson(const nlohmann::json &json)
RetainTree(iot::mqtt::server::broker::Broker *broker)
void sendPublish(iot::mqtt::server::broker::Message &message, uint8_t qoS, bool retain)
Definition Session.cpp:44
std::deque< Message > messageQueue
Definition Session.h:62
nlohmann::json toJson() const final
Definition Session.cpp:99
Session(iot::mqtt::server::Mqtt *mqtt)
Definition Session.cpp:40
void fromJson(const nlohmann::json &json)
Definition Session.cpp:109
Session * renew(iot::mqtt::server::Mqtt *mqtt)
Definition Session.cpp:81
bool isOwnedBy(const iot::mqtt::server::Mqtt *mqtt) const
Definition Session.cpp:95