SNode.C
Loading...
Searching...
No Matches
iot::mqtt::packets::Connect Class Reference

#include <Connect.h>

Inheritance diagram for iot::mqtt::packets::Connect:
Collaboration diagram for iot::mqtt::packets::Connect:

Public Member Functions

 Connect ()
 
 Connect (const std::string &clientId, 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, bool loopPrevention)
 
std::string getProtocol () const
 
uint8_t getLevel () const
 
uint8_t getConnectFlags () const
 
uint16_t getKeepAlive () const
 
std::string getClientId () const
 
bool getUsernameFlag () const
 
bool getPasswordFlag () const
 
bool getWillRetain () const
 
uint8_t getWillQoS () const
 
bool getWillFlag () const
 
bool getCleanSession () const
 
bool getReflect () const
 
std::string getWillTopic () const
 
std::string getWillMessage () const
 
std::string getUsername () const
 
std::string getPassword () const
 
- Public Member Functions inherited from iot::mqtt::ControlPacket
 ControlPacket (uint8_t type, const std::string &name)
 
 ControlPacket (const ControlPacket &)=default
 
 ControlPacket (ControlPacket &&)=default
 
virtual ~ControlPacket ()
 
ControlPacketoperator= (const ControlPacket &)=default
 
ControlPacketoperator= (ControlPacket &&)=default
 
std::vector< char > serialize () const
 
const std::string & getName () const
 
uint8_t getType () const
 
uint8_t getFlags () const
 

Protected Attributes

iot::mqtt::types::String protocol
 
iot::mqtt::types::UInt8 level
 
iot::mqtt::types::UInt8 connectFlags
 
iot::mqtt::types::UInt16 keepAlive
 
iot::mqtt::types::String clientId
 
iot::mqtt::types::String willTopic
 
iot::mqtt::types::String willMessage
 
iot::mqtt::types::String username
 
iot::mqtt::types::String password
 
bool usernameFlag = false
 
bool passwordFlag = false
 
bool willRetain = false
 
uint8_t willQoS = 0
 
bool willFlag = false
 
bool cleanSession = false
 
bool reflect = true
 
bool reserved = false
 
- Protected Attributes inherited from iot::mqtt::ControlPacket
uint8_t flags = 0
 

Private Member Functions

std::vector< char > serializeVP () const override
 

Detailed Description

Definition at line 40 of file Connect.h.

Constructor & Destructor Documentation

◆ Connect() [1/2]

iot::mqtt::packets::Connect::Connect ( )

Definition at line 30 of file Connect.cpp.

32 }
#define MQTT_CONNECT
Definition Connect.h:36

References Connect().

Referenced by Connect(), and Connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Connect() [2/2]

iot::mqtt::packets::Connect::Connect ( const std::string & clientId,
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,
bool loopPrevention )

Definition at line 34 of file Connect.cpp.

44 : Connect() {
45 this->protocol = "MQTT";
46 this->level =
47 MQTT_VERSION_3_1_1 | (loopPrevention ? 0x80 : 0x00); // msb 1 -> do not reflect messages to origin (try_private in mosquitto)
48 this->keepAlive = keepAlive;
49 this->clientId = clientId;
50 this->willTopic = willTopic;
51 this->willMessage = willMessage;
52 this->willQoS = willQoS;
53 this->willRetain = willRetain;
54 this->willFlag = !willMessage.empty();
55 this->username = username;
56 this->usernameFlag = !username.empty();
57 this->password = password;
58 this->passwordFlag = !password.empty();
59
60 this->connectFlags = static_cast<uint8_t>((!usernameFlag ? 0 : 0x80) | (!passwordFlag ? 0 : 0x40) | (!willRetain ? 0 : 0x20) |
61 ((willQoS << 3) & 0x18) | (!willFlag ? 0 : 0x04) | (!cleanSession ? 0 : 0x02));
62 }
iot::mqtt::types::String willMessage
Definition Connect.h:86
iot::mqtt::types::String protocol
Definition Connect.h:80
iot::mqtt::types::String willTopic
Definition Connect.h:85
iot::mqtt::types::UInt8 connectFlags
Definition Connect.h:82
iot::mqtt::types::String username
Definition Connect.h:87
iot::mqtt::types::UInt8 level
Definition Connect.h:81
iot::mqtt::types::String clientId
Definition Connect.h:84
iot::mqtt::types::String password
Definition Connect.h:88
iot::mqtt::types::UInt16 keepAlive
Definition Connect.h:83
#define MQTT_VERSION_3_1_1
Definition Connect.h:38

References Connect(), passwordFlag, usernameFlag, willFlag, willQoS, and willRetain.

Here is the call graph for this function:

Member Function Documentation

◆ getCleanSession()

bool iot::mqtt::packets::Connect::getCleanSession ( ) const

Definition at line 138 of file Connect.cpp.

138 {
139 return cleanSession;
140 }

References cleanSession.

◆ getClientId()

std::string iot::mqtt::packets::Connect::getClientId ( ) const

Definition at line 114 of file Connect.cpp.

114 {
115 return clientId;
116 }

◆ getConnectFlags()

uint8_t iot::mqtt::packets::Connect::getConnectFlags ( ) const

Definition at line 106 of file Connect.cpp.

106 {
107 return connectFlags;
108 }

◆ getKeepAlive()

uint16_t iot::mqtt::packets::Connect::getKeepAlive ( ) const

Definition at line 110 of file Connect.cpp.

110 {
111 return keepAlive;
112 }

◆ getLevel()

uint8_t iot::mqtt::packets::Connect::getLevel ( ) const

Definition at line 102 of file Connect.cpp.

102 {
103 return level;
104 }

◆ getPassword()

std::string iot::mqtt::packets::Connect::getPassword ( ) const

Definition at line 158 of file Connect.cpp.

158 {
159 return password;
160 }

◆ getPasswordFlag()

bool iot::mqtt::packets::Connect::getPasswordFlag ( ) const

Definition at line 122 of file Connect.cpp.

122 {
123 return passwordFlag;
124 }

References passwordFlag.

◆ getProtocol()

std::string iot::mqtt::packets::Connect::getProtocol ( ) const

Definition at line 98 of file Connect.cpp.

98 {
99 return protocol;
100 }

◆ getReflect()

bool iot::mqtt::packets::Connect::getReflect ( ) const

Definition at line 142 of file Connect.cpp.

142 {
143 return reflect;
144 }

References reflect.

◆ getUsername()

std::string iot::mqtt::packets::Connect::getUsername ( ) const

Definition at line 154 of file Connect.cpp.

154 {
155 return username;
156 }

◆ getUsernameFlag()

bool iot::mqtt::packets::Connect::getUsernameFlag ( ) const

Definition at line 118 of file Connect.cpp.

118 {
119 return usernameFlag;
120 }

References usernameFlag.

◆ getWillFlag()

bool iot::mqtt::packets::Connect::getWillFlag ( ) const

Definition at line 134 of file Connect.cpp.

134 {
135 return willFlag;
136 }

References willFlag.

◆ getWillMessage()

std::string iot::mqtt::packets::Connect::getWillMessage ( ) const

Definition at line 150 of file Connect.cpp.

150 {
151 return willMessage;
152 }

◆ getWillQoS()

uint8_t iot::mqtt::packets::Connect::getWillQoS ( ) const

Definition at line 130 of file Connect.cpp.

130 {
131 return willQoS;
132 }

References willQoS.

◆ getWillRetain()

bool iot::mqtt::packets::Connect::getWillRetain ( ) const

Definition at line 126 of file Connect.cpp.

126 {
127 return willRetain;
128 }

References willRetain.

◆ getWillTopic()

std::string iot::mqtt::packets::Connect::getWillTopic ( ) const

Definition at line 146 of file Connect.cpp.

146 {
147 return willTopic;
148 }

◆ serializeVP()

std::vector< char > iot::mqtt::packets::Connect::serializeVP ( ) const
overrideprivatevirtual

Implements iot::mqtt::ControlPacket.

Definition at line 64 of file Connect.cpp.

64 {
65 std::vector<char> packet(protocol.serialize());
66
67 std::vector<char> tmpVector = level.serialize();
68 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
69
70 tmpVector = connectFlags.serialize();
71 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
72
73 tmpVector = keepAlive.serialize();
74 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
75
76 tmpVector = clientId.serialize();
77 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
78
79 if (willFlag) {
80 tmpVector = willTopic.serialize();
81 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
82
83 tmpVector = willMessage.serialize();
84 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
85 }
86 if (usernameFlag) {
87 tmpVector = username.serialize();
88 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
89 }
90 if (passwordFlag) {
91 tmpVector = password.serialize();
92 packet.insert(packet.end(), tmpVector.begin(), tmpVector.end());
93 }
94
95 return packet;
96 }
std::vector< char > serialize() const override
Definition String.cpp:75
virtual std::vector< char > serialize() const
Definition TypeBase.hpp:61

References passwordFlag, usernameFlag, and willFlag.

Member Data Documentation

◆ cleanSession

bool iot::mqtt::packets::Connect::cleanSession = false
protected

Definition at line 95 of file Connect.h.

Referenced by getCleanSession().

◆ clientId

iot::mqtt::types::String iot::mqtt::packets::Connect::clientId
protected

Definition at line 84 of file Connect.h.

◆ connectFlags

iot::mqtt::types::UInt8 iot::mqtt::packets::Connect::connectFlags
protected

Definition at line 82 of file Connect.h.

◆ keepAlive

iot::mqtt::types::UInt16 iot::mqtt::packets::Connect::keepAlive
protected

Definition at line 83 of file Connect.h.

◆ level

iot::mqtt::types::UInt8 iot::mqtt::packets::Connect::level
protected

Definition at line 81 of file Connect.h.

◆ password

iot::mqtt::types::String iot::mqtt::packets::Connect::password
protected

Definition at line 88 of file Connect.h.

◆ passwordFlag

bool iot::mqtt::packets::Connect::passwordFlag = false
protected

Definition at line 91 of file Connect.h.

Referenced by Connect(), getPasswordFlag(), and serializeVP().

◆ protocol

iot::mqtt::types::String iot::mqtt::packets::Connect::protocol
protected

Definition at line 80 of file Connect.h.

◆ reflect

bool iot::mqtt::packets::Connect::reflect = true
protected

Definition at line 96 of file Connect.h.

Referenced by getReflect().

◆ reserved

bool iot::mqtt::packets::Connect::reserved = false
protected

Definition at line 97 of file Connect.h.

◆ username

iot::mqtt::types::String iot::mqtt::packets::Connect::username
protected

Definition at line 87 of file Connect.h.

◆ usernameFlag

bool iot::mqtt::packets::Connect::usernameFlag = false
protected

Definition at line 90 of file Connect.h.

Referenced by Connect(), getUsernameFlag(), and serializeVP().

◆ willFlag

bool iot::mqtt::packets::Connect::willFlag = false
protected

Definition at line 94 of file Connect.h.

Referenced by Connect(), getWillFlag(), and serializeVP().

◆ willMessage

iot::mqtt::types::String iot::mqtt::packets::Connect::willMessage
protected

Definition at line 86 of file Connect.h.

◆ willQoS

uint8_t iot::mqtt::packets::Connect::willQoS = 0
protected

Definition at line 93 of file Connect.h.

Referenced by Connect(), and getWillQoS().

◆ willRetain

bool iot::mqtt::packets::Connect::willRetain = false
protected

Definition at line 92 of file Connect.h.

Referenced by Connect(), and getWillRetain().

◆ willTopic

iot::mqtt::types::String iot::mqtt::packets::Connect::willTopic
protected

Definition at line 85 of file Connect.h.


The documentation for this class was generated from the following files: