SNode.C
Loading...
Searching...
No Matches
TypeBase.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_TYPES_TYPEBASE_H
21#define IOT_MQTT_TYPES_TYPEBASE_H
22
23namespace iot::mqtt {
24 class MqttContext;
25}
26
27#ifndef DOXYGEN_SHOULD_SKIP_THIS
28
29#include <cstddef>
30#include <vector>
31
32#endif // DOXYGEN_SHOULD_SKIP_THIS
33
34namespace iot::mqtt::types {
35
36 template <typename ValueTypeT>
37 class TypeBase {
38 protected:
39 using ValueType = ValueTypeT;
40
41 public:
42 explicit TypeBase(std::size_t size = sizeof(ValueType));
43 TypeBase(const TypeBase&) = default;
44 TypeBase(TypeBase&&) noexcept = default;
45
46 virtual ~TypeBase() = default;
47
48 TypeBase& operator=(const TypeBase&) = default;
49 TypeBase& operator=(TypeBase&&) noexcept = default;
50
51 virtual std::size_t deserialize(iot::mqtt::MqttContext* mqttContext);
52 virtual std::vector<char> serialize() const;
53
54 void setSize(std::size_t size);
55
56 std::size_t size();
57
58 bool isComplete() const;
59
60 virtual void reset(std::size_t size = sizeof(ValueType));
61
62 protected:
63 std::vector<char> value;
64
65 std::size_t length = 0;
66 std::size_t needed = 0;
67
68 bool complete = false;
69
70 int state = 0;
71 };
72
73} // namespace iot::mqtt::types
74
75#endif // IOT_MQTT_TYPES_TYPEBASE_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