SNode.C
Loading...
Searching...
No Matches
iot::mqtt::server::Mqtt Class Reference

#include <Mqtt.h>

Inheritance diagram for iot::mqtt::server::Mqtt:
Collaboration diagram for iot::mqtt::server::Mqtt:

Public Member Functions

 Mqtt (const std::string &connectionName, const std::shared_ptr< broker::Broker > &broker)
 
 ~Mqtt () override
 
void subscribe (const std::string &topic, uint8_t qoS) const
 
void unsubscribe (const std::string &topic) const
 
void sendConnack (uint8_t returnCode, uint8_t flags) const
 
void sendSuback (uint16_t packetIdentifier, const std::list< uint8_t > &returnCodes) const
 
void sendUnsuback (uint16_t packetIdentifier) const
 
void sendPingresp () const
 
std::list< std::string > getSubscriptions () const
 
std::string getProtocol () const
 
uint8_t getLevel () const
 
uint8_t getConnectFlags () const
 
uint16_t getKeepAlive () const
 
std::string getClientId () const
 
std::string getWillTopic () const
 
std::string getWillMessage () const
 
std::string getUsername () const
 
std::string getPassword () const
 
bool getUsernameFlag () const
 
bool getPasswordFlag () const
 
bool getWillRetain () const
 
uint8_t getWillQoS () const
 
bool getWillFlag () const
 
bool getCleanSession () const
 
bool getReflect () const
 
- Public Member Functions inherited from iot::mqtt::Mqtt
 Mqtt (const std::string &connectionName)
 
 Mqtt (const std::string &connectionName, const std::string &clientId)
 
 Mqtt (Mqtt &&)=delete
 
 Mqtt (const Mqtt &)=delete
 
Mqttoperator= (Mqtt &&)=delete
 
Mqttoperator= (const Mqtt &)=delete
 
virtual void onConnected ()
 
virtual void onDisconnected ()
 
const std::string & getConnectionName () const
 
const MqttContextgetMqttContext () const
 
void sendPublish (const std::string &topic, const std::string &message, uint8_t qoS, bool retain)
 
void sendPuback (uint16_t packetIdentifier) const
 
void sendPubrec (uint16_t packetIdentifier) const
 
void sendPubrel (uint16_t packetIdentifier) const
 
void sendPubcomp (uint16_t packetIdentifier) const
 

Protected Member Functions

bool onSignal (int sig) override
 
- Protected Member Functions inherited from iot::mqtt::Mqtt
void initSession (Session *session, utils::Timeval keepAlive)
 
virtual void onPublish (const iot::mqtt::packets::Publish &publish)
 
virtual void onPuback (const iot::mqtt::packets::Puback &puback)
 
virtual void onPubrec (const iot::mqtt::packets::Pubrec &pubrec)
 
virtual void onPubrel (const iot::mqtt::packets::Pubrel &pubrel)
 
virtual void onPubcomp (const iot::mqtt::packets::Pubcomp &pubcomp)
 
bool _onPublish (const iot::mqtt::packets::Publish &publish)
 
void _onPuback (const iot::mqtt::packets::Puback &puback)
 
void _onPubrec (const iot::mqtt::packets::Pubrec &pubrec)
 
void _onPubrel (const iot::mqtt::packets::Pubrel &pubrel)
 
void _onPubcomp (const iot::mqtt::packets::Pubcomp &pubcomp)
 
uint16_t getPacketIdentifier ()
 
void send (const iot::mqtt::ControlPacket &controlPacket) const
 
void printVP (const iot::mqtt::ControlPacket &packet) const
 
void printFixedHeader (const iot::mqtt::FixedHeader &fixedHeader) const
 

Protected Attributes

std::string protocol
 
uint8_t level = 0
 
uint8_t connectFlags = 0
 
uint16_t keepAlive = 0
 
std::string willTopic
 
std::string willMessage
 
std::string username
 
std::string password
 
bool usernameFlag = false
 
bool passwordFlag = false
 
bool willRetain = false
 
uint8_t willQoS = 0
 
bool willFlag = false
 
bool cleanSession = false
 
bool reflect = true
 
std::shared_ptr< iot::mqtt::server::broker::Brokerbroker
 
- Protected Attributes inherited from iot::mqtt::Mqtt
std::string connectionName
 
std::string clientId
 
MqttContextmqttContext = nullptr
 

Private Types

using Super = iot::mqtt::Mqtt
 

Private Member Functions

iot::mqtt::ControlPacketDeserializercreateControlPacketDeserializer (iot::mqtt::FixedHeader &fixedHeader) final
 
void deliverPacket (iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer) override
 
bool initSession (const utils::Timeval &keepAlive)
 
void releaseSession ()
 
virtual void onConnect (const iot::mqtt::packets::Connect &connect)
 
virtual void onSubscribe (const iot::mqtt::packets::Subscribe &subscribe)
 
virtual void onUnsubscribe (const iot::mqtt::packets::Unsubscribe &unsubscribe)
 
virtual void onPingreq (const iot::mqtt::packets::Pingreq &pingreq)
 
virtual void onDisconnect (const iot::mqtt::packets::Disconnect &disconnect)
 
void _onConnect (const iot::mqtt::server::packets::Connect &connect)
 
void _onPublish (const iot::mqtt::server::packets::Publish &publish)
 
void _onSubscribe (const iot::mqtt::server::packets::Subscribe &subscribe)
 
void _onUnsubscribe (const iot::mqtt::server::packets::Unsubscribe &unsubscribe)
 
void _onPingreq (const iot::mqtt::server::packets::Pingreq &pingreq)
 
void _onDisconnect (const iot::mqtt::server::packets::Disconnect &disconnect)
 
void initSession (Session *session, utils::Timeval keepAlive)
 

Friends

class iot::mqtt::server::packets::Connect
 
class iot::mqtt::server::packets::Subscribe
 
class iot::mqtt::server::packets::Unsubscribe
 
class iot::mqtt::server::packets::Pingreq
 
class iot::mqtt::server::packets::Disconnect
 
class iot::mqtt::server::packets::Publish
 
class iot::mqtt::server::packets::Pubcomp
 
class iot::mqtt::server::packets::Pubrec
 
class iot::mqtt::server::packets::Puback
 
class iot::mqtt::server::packets::Pubrel
 

Additional Inherited Members

- Static Public Member Functions inherited from iot::mqtt::Mqtt
static std::string toHexString (const std::vector< char > &data)
 
static std::string toHexString (const std::string &data)
 

Detailed Description

Definition at line 87 of file Mqtt.h.

Member Typedef Documentation

◆ Super

Definition at line 89 of file Mqtt.h.

Constructor & Destructor Documentation

◆ Mqtt()

iot::mqtt::server::Mqtt::Mqtt ( const std::string &  connectionName,
const std::shared_ptr< broker::Broker > &  broker 
)
explicit

Definition at line 73 of file Mqtt.cpp.

75 , broker(broker) {
76 }
std::string connectionName
Definition Mqtt.h:142
std::shared_ptr< iot::mqtt::server::broker::Broker > broker
Definition Mqtt.h:168
iot::mqtt::Mqtt Super
Definition Mqtt.h:89

References iot::mqtt::Mqtt::Mqtt().

Here is the call graph for this function:

◆ ~Mqtt()

iot::mqtt::server::Mqtt::~Mqtt ( )
overridevirtual

Reimplemented from iot::mqtt::Mqtt.

Definition at line 78 of file Mqtt.cpp.

78 {
80
81 if (willFlag) {
83 }
84 }
std::string clientId
Definition Mqtt.h:143
std::string willMessage
Definition Mqtt.h:156
std::string willTopic
Definition Mqtt.h:155

References iot::mqtt::Mqtt::clientId, iot::mqtt::server::broker::Broker::publish(), releaseSession(), willFlag, willMessage, willQoS, willRetain, and willTopic.

Here is the call graph for this function:

Member Function Documentation

◆ _onConnect()

void iot::mqtt::server::Mqtt::_onConnect ( const iot::mqtt::server::packets::Connect connect)
private

Definition at line 221 of file Mqtt.cpp.

221 {
222 LOG(INFO) << connectionName << " MQTT Broker: Protocol: " << connect.getProtocol();
223 LOG(INFO) << connectionName << " MQTT Broker: Version: " << static_cast<uint16_t>(connect.getLevel());
224 LOG(INFO) << connectionName << " MQTT Broker: ConnectFlags: 0x" << std::hex << std::setfill('0') << std::setw(2)
225 << static_cast<uint16_t>(connect.getConnectFlags()) << std::dec << std::setw(0);
226 LOG(INFO) << connectionName << " MQTT Broker: KeepAlive: " << connect.getKeepAlive();
227 LOG(INFO) << connectionName << " MQTT Broker: ClientID: " << connect.getClientId();
228 LOG(INFO) << connectionName << " MQTT Broker: CleanSession: " << connect.getCleanSession();
229
230 if (connect.getWillFlag()) {
231 LOG(INFO) << connectionName << " MQTT Broker: WillTopic: " << connect.getWillTopic();
232 LOG(INFO) << connectionName << " MQTT Broker: WillMessage: " << connect.getWillMessage();
233 LOG(INFO) << connectionName << " MQTT Broker: WillQoS: " << static_cast<uint16_t>(connect.getWillQoS());
234 LOG(INFO) << connectionName << " MQTT Broker: WillRetain: " << connect.getWillRetain();
235 }
236 if (connect.getUsernameFlag()) {
237 LOG(INFO) << connectionName << " MQTT Broker: Username: " << connect.getUsername();
238 }
239 if (connect.getPasswordFlag()) {
240 LOG(INFO) << connectionName << " MQTT Broker: Password: " << connect.getPassword();
241 }
242
243 if (connect.getProtocol() != "MQTT") {
244 LOG(ERROR) << connectionName << " MQTT Broker: Wrong Protocol: " << connect.getProtocol();
245 mqttContext->end(true);
246 } else if ((connect.getLevel()) != MQTT_VERSION_3_1_1) {
247 LOG(ERROR) << connectionName << " MQTT Broker: Wrong Protocol Level: " << MQTT_VERSION_3_1_1 << " != " << connect.getLevel();
249
250 mqttContext->end(true);
251 } else if (connect.isFakedClientId() && !connect.getCleanSession()) {
252 LOG(ERROR) << connectionName << " MQTT Broker: Resume session but no ClientId present";
254
255 mqttContext->end(true);
256 } else {
257 // V-Header
258 protocol = connect.getProtocol();
259 level = connect.getLevel();
260 reflect = connect.getReflect();
261 connectFlags = connect.getConnectFlags();
262 keepAlive = connect.getKeepAlive();
263
264 // Payload
265 clientId = connect.getClientId();
266 willTopic = connect.getWillTopic();
267 willMessage = connect.getWillMessage();
268 username = connect.getUsername();
269 password = connect.getPassword();
270
271 // Derived from flags
272 usernameFlag = connect.getUsernameFlag();
273 passwordFlag = connect.getPasswordFlag();
274 willRetain = connect.getWillRetain();
275 willQoS = connect.getWillQoS();
276 willFlag = connect.getWillFlag();
277 cleanSession = connect.getCleanSession();
278
279 if (initSession(keepAlive)) {
280 onConnect(connect);
281 } else {
282 mqttContext->end(true);
283 }
284 }
285 }
virtual void end(bool fatal=false)=0
MqttContext * mqttContext
Definition Mqtt.h:158
virtual void onConnect(const iot::mqtt::packets::Connect &connect)
Definition Mqtt.cpp:206
std::string password
Definition Mqtt.h:158
bool initSession(const utils::Timeval &keepAlive)
Definition Mqtt.cpp:155
void sendConnack(uint8_t returnCode, uint8_t flags) const
Definition Mqtt.cpp:356
std::string username
Definition Mqtt.h:157
std::string protocol
Definition Mqtt.h:150
#define MQTT_SESSION_NEW
Definition Connack.h:66
#define MQTT_CONNACK_UNACEPTABLEVERSION
Definition Connack.h:60
#define MQTT_CONNACK_IDENTIFIERREJECTED
Definition Connack.h:61
#define MQTT_VERSION_3_1_1
Definition Connect.h:60
int connect(int sockfd, const sockaddr *addr, socklen_t addrlen)
Definition socket.cpp:76

References cleanSession, iot::mqtt::Mqtt::clientId, connectFlags, iot::mqtt::Mqtt::connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Connect::getCleanSession(), iot::mqtt::packets::Connect::getClientId(), iot::mqtt::packets::Connect::getConnectFlags(), iot::mqtt::packets::Connect::getKeepAlive(), iot::mqtt::packets::Connect::getLevel(), iot::mqtt::packets::Connect::getPassword(), iot::mqtt::packets::Connect::getPasswordFlag(), iot::mqtt::packets::Connect::getProtocol(), iot::mqtt::packets::Connect::getReflect(), iot::mqtt::packets::Connect::getUsername(), iot::mqtt::packets::Connect::getUsernameFlag(), iot::mqtt::packets::Connect::getWillFlag(), iot::mqtt::packets::Connect::getWillMessage(), iot::mqtt::packets::Connect::getWillQoS(), iot::mqtt::packets::Connect::getWillRetain(), iot::mqtt::packets::Connect::getWillTopic(), initSession(), iot::mqtt::server::packets::Connect::isFakedClientId(), keepAlive, level, iot::mqtt::Mqtt::mqttContext, onConnect(), password, passwordFlag, protocol, reflect, sendConnack(), username, usernameFlag, willFlag, willMessage, willQoS, willRetain, and willTopic.

Referenced by iot::mqtt::server::packets::Connect::deliverPacket().

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

◆ _onDisconnect()

void iot::mqtt::server::Mqtt::_onDisconnect ( const iot::mqtt::server::packets::Disconnect disconnect)
private

Definition at line 348 of file Mqtt.cpp.

348 {
349 willFlag = false;
350
351 onDisconnect(disconnect);
352
354 }
virtual void onDisconnect(const iot::mqtt::packets::Disconnect &disconnect)
Definition Mqtt.cpp:218

References onDisconnect(), releaseSession(), and willFlag.

Referenced by iot::mqtt::server::packets::Disconnect::deliverPacket().

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

◆ _onPingreq()

void iot::mqtt::server::Mqtt::_onPingreq ( const iot::mqtt::server::packets::Pingreq pingreq)
private

Definition at line 342 of file Mqtt.cpp.

342 {
343 sendPingresp();
344
345 onPingreq(pingreq);
346 }
virtual void onPingreq(const iot::mqtt::packets::Pingreq &pingreq)
Definition Mqtt.cpp:215
void sendPingresp() const
Definition Mqtt.cpp:368

References onPingreq(), and sendPingresp().

Referenced by iot::mqtt::server::packets::Pingreq::deliverPacket().

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

◆ _onPublish()

void iot::mqtt::server::Mqtt::_onPublish ( const iot::mqtt::server::packets::Publish publish)
private

Definition at line 287 of file Mqtt.cpp.

287 {
288 if (Super::_onPublish(publish)) {
289 broker->publish(clientId, publish.getTopic(), publish.getMessage(), publish.getQoS(), publish.getRetain());
290
291 onPublish(publish);
292 }
293 }
virtual void onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:253
bool _onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:268
uint8_t getQoS() const
Definition Publish.cpp:85
std::string getTopic() const
Definition Publish.cpp:93
std::string getMessage() const
Definition Publish.cpp:97

References iot::mqtt::Mqtt::_onPublish(), iot::mqtt::Mqtt::clientId, iot::mqtt::packets::Publish::getMessage(), iot::mqtt::packets::Publish::getQoS(), iot::mqtt::packets::Publish::getRetain(), iot::mqtt::packets::Publish::getTopic(), iot::mqtt::Mqtt::onPublish(), and iot::mqtt::server::broker::Broker::publish().

Referenced by iot::mqtt::server::packets::Publish::deliverPacket().

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

◆ _onSubscribe()

void iot::mqtt::server::Mqtt::_onSubscribe ( const iot::mqtt::server::packets::Subscribe subscribe)
private

Definition at line 295 of file Mqtt.cpp.

295 {
296 if (subscribe.getPacketIdentifier() == 0) {
297 LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing";
298 mqttContext->end(true);
299 } else {
300 LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4)
301 << subscribe.getPacketIdentifier();
302
303 for (const iot::mqtt::Topic& topic : subscribe.getTopics()) {
304 LOG(INFO) << connectionName << " MQTT Broker: Topic filter: '" << topic.getName()
305 << "', QoS: " << static_cast<uint16_t>(topic.getQoS());
306 }
307
308 std::list<uint8_t> returnCodes;
309 for (const iot::mqtt::Topic& topic : subscribe.getTopics()) {
310 const uint8_t returnCode = broker->subscribe(clientId, topic.getName(), topic.getQoS());
311 returnCodes.push_back(returnCode);
312 }
313
314 sendSuback(subscribe.getPacketIdentifier(), returnCodes);
315
317 }
318 }
void subscribe(const std::string &topic, uint8_t qoS) const
Definition Mqtt.cpp:86
void sendSuback(uint16_t packetIdentifier, const std::list< uint8_t > &returnCodes) const
Definition Mqtt.cpp:360
virtual void onSubscribe(const iot::mqtt::packets::Subscribe &subscribe)
Definition Mqtt.cpp:209

References iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::Topic::getName(), iot::mqtt::packets::Subscribe::getPacketIdentifier(), iot::mqtt::Topic::getQoS(), iot::mqtt::packets::Subscribe::getTopics(), iot::mqtt::Mqtt::mqttContext, onSubscribe(), sendSuback(), and iot::mqtt::server::broker::Broker::subscribe().

Referenced by iot::mqtt::server::packets::Subscribe::deliverPacket().

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

◆ _onUnsubscribe()

void iot::mqtt::server::Mqtt::_onUnsubscribe ( const iot::mqtt::server::packets::Unsubscribe unsubscribe)
private

Definition at line 320 of file Mqtt.cpp.

320 {
321 if (unsubscribe.getPacketIdentifier() == 0) {
322 LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing";
323 mqttContext->end(true);
324 } else {
325 LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4)
326 << unsubscribe.getPacketIdentifier();
327
328 for (const std::string& topic : unsubscribe.getTopics()) {
329 LOG(INFO) << connectionName << " MQTT Broker: Topic: " << topic;
330 }
331
332 for (const std::string& topic : unsubscribe.getTopics()) {
333 broker->unsubscribe(clientId, topic);
334 }
335
336 sendUnsuback(unsubscribe.getPacketIdentifier());
337
339 }
340 }
virtual void onUnsubscribe(const iot::mqtt::packets::Unsubscribe &unsubscribe)
Definition Mqtt.cpp:212
void sendUnsuback(uint16_t packetIdentifier) const
Definition Mqtt.cpp:364
void unsubscribe(const std::string &topic) const
Definition Mqtt.cpp:90

References iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Unsubscribe::getPacketIdentifier(), iot::mqtt::packets::Unsubscribe::getTopics(), iot::mqtt::Mqtt::mqttContext, onUnsubscribe(), sendUnsuback(), and iot::mqtt::server::broker::Broker::unsubscribe().

Referenced by iot::mqtt::server::packets::Unsubscribe::deliverPacket().

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

◆ createControlPacketDeserializer()

iot::mqtt::ControlPacketDeserializer * iot::mqtt::server::Mqtt::createControlPacketDeserializer ( iot::mqtt::FixedHeader fixedHeader)
finalprivatevirtual

Implements iot::mqtt::Mqtt.

Definition at line 99 of file Mqtt.cpp.

99 {
101
102 switch (fixedHeader.getType()) {
103 case MQTT_CONNECT:
106 break;
107 case MQTT_PUBLISH:
110 break;
111 case MQTT_PUBACK:
114 break;
115 case MQTT_PUBREC:
118 break;
119 case MQTT_PUBREL:
122 break;
123 case MQTT_PUBCOMP:
126 break;
127 case MQTT_SUBSCRIBE:
130 break;
131 case MQTT_UNSUBSCRIBE:
134 break;
135 case MQTT_PINGREQ:
138 break;
139 case MQTT_DISCONNECT:
142 break;
143 default:
145 break;
146 }
147
149 }
uint8_t getType() const
uint32_t getRemainingLength() const
uint8_t getFlags() const
iot::mqtt::FixedHeader fixedHeader
Definition Mqtt.h:146
iot::mqtt::ControlPacketDeserializer * controlPacketDeserializer
Definition Mqtt.h:147
#define MQTT_CONNECT
Definition Connect.h:58
#define MQTT_DISCONNECT
Definition Disconnect.h:55
#define MQTT_PINGREQ
Definition Pingreq.h:55
#define MQTT_PUBACK
Definition Puback.h:57
#define MQTT_PUBCOMP
Definition Pubcomp.h:57
#define MQTT_PUBLISH
Definition Publish.h:58
#define MQTT_PUBREC
Definition Pubrec.h:57
#define MQTT_PUBREL
Definition Pubrel.h:57
#define MQTT_SUBSCRIBE
Definition Subscribe.h:59
#define MQTT_UNSUBSCRIBE
Definition Unsubscribe.h:59

References iot::mqtt::server::packets::Connect::Connect(), iot::mqtt::server::packets::Disconnect::Disconnect(), iot::mqtt::FixedHeader::getFlags(), iot::mqtt::FixedHeader::getRemainingLength(), iot::mqtt::FixedHeader::getType(), iot::mqtt::server::packets::Pingreq::Pingreq(), iot::mqtt::server::packets::Puback::Puback(), iot::mqtt::server::packets::Pubcomp::Pubcomp(), iot::mqtt::server::packets::Publish::Publish(), iot::mqtt::server::packets::Pubrec::Pubrec(), iot::mqtt::server::packets::Pubrel::Pubrel(), iot::mqtt::server::packets::Subscribe::Subscribe(), and iot::mqtt::server::packets::Unsubscribe::Unsubscribe().

Here is the call graph for this function:

◆ deliverPacket()

void iot::mqtt::server::Mqtt::deliverPacket ( iot::mqtt::ControlPacketDeserializer controlPacketDeserializer)
overrideprivatevirtual

Implements iot::mqtt::Mqtt.

Definition at line 151 of file Mqtt.cpp.

151 {
153 }
void deliverPacket(iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer) override
Definition Mqtt.cpp:151

References iot::mqtt::server::ControlPacketDeserializer::deliverPacket().

Here is the call graph for this function:

◆ getCleanSession()

bool iot::mqtt::server::Mqtt::getCleanSession ( ) const

Definition at line 432 of file Mqtt.cpp.

432 {
433 return cleanSession;
434 }

References cleanSession.

◆ getClientId()

std::string iot::mqtt::server::Mqtt::getClientId ( ) const

Definition at line 392 of file Mqtt.cpp.

392 {
393 return clientId;
394 }

References iot::mqtt::Mqtt::clientId.

Referenced by iot::mqtt::server::broker::Session::sendPublish().

Here is the caller graph for this function:

◆ getConnectFlags()

uint8_t iot::mqtt::server::Mqtt::getConnectFlags ( ) const

Definition at line 384 of file Mqtt.cpp.

384 {
385 return connectFlags;
386 }

References connectFlags.

◆ getKeepAlive()

uint16_t iot::mqtt::server::Mqtt::getKeepAlive ( ) const

Definition at line 388 of file Mqtt.cpp.

388 {
389 return keepAlive;
390 }

References keepAlive.

◆ getLevel()

uint8_t iot::mqtt::server::Mqtt::getLevel ( ) const

Definition at line 380 of file Mqtt.cpp.

380 {
381 return level;
382 }

References level.

◆ getPassword()

std::string iot::mqtt::server::Mqtt::getPassword ( ) const

Definition at line 408 of file Mqtt.cpp.

408 {
409 return password;
410 }

References password.

◆ getPasswordFlag()

bool iot::mqtt::server::Mqtt::getPasswordFlag ( ) const

Definition at line 416 of file Mqtt.cpp.

416 {
417 return passwordFlag;
418 }

References passwordFlag.

◆ getProtocol()

std::string iot::mqtt::server::Mqtt::getProtocol ( ) const

Definition at line 376 of file Mqtt.cpp.

376 {
377 return protocol;
378 }

References protocol.

◆ getReflect()

bool iot::mqtt::server::Mqtt::getReflect ( ) const

Definition at line 436 of file Mqtt.cpp.

436 {
437 return reflect;
438 }

References reflect.

Referenced by iot::mqtt::server::broker::Session::sendPublish().

Here is the caller graph for this function:

◆ getSubscriptions()

std::list< std::string > iot::mqtt::server::Mqtt::getSubscriptions ( ) const

Definition at line 372 of file Mqtt.cpp.

372 {
373 return broker->getSubscriptions(clientId);
374 }

References iot::mqtt::Mqtt::clientId, and iot::mqtt::server::broker::Broker::getSubscriptions().

Here is the call graph for this function:

◆ getUsername()

std::string iot::mqtt::server::Mqtt::getUsername ( ) const

Definition at line 404 of file Mqtt.cpp.

404 {
405 return username;
406 }

References username.

◆ getUsernameFlag()

bool iot::mqtt::server::Mqtt::getUsernameFlag ( ) const

Definition at line 412 of file Mqtt.cpp.

412 {
413 return usernameFlag;
414 }

References usernameFlag.

◆ getWillFlag()

bool iot::mqtt::server::Mqtt::getWillFlag ( ) const

Definition at line 428 of file Mqtt.cpp.

428 {
429 return willFlag;
430 }

References willFlag.

◆ getWillMessage()

std::string iot::mqtt::server::Mqtt::getWillMessage ( ) const

Definition at line 400 of file Mqtt.cpp.

400 {
401 return willMessage;
402 }

References willMessage.

◆ getWillQoS()

uint8_t iot::mqtt::server::Mqtt::getWillQoS ( ) const

Definition at line 424 of file Mqtt.cpp.

424 {
425 return willQoS;
426 }

References willQoS.

◆ getWillRetain()

bool iot::mqtt::server::Mqtt::getWillRetain ( ) const

Definition at line 420 of file Mqtt.cpp.

420 {
421 return willRetain;
422 }

References willRetain.

◆ getWillTopic()

std::string iot::mqtt::server::Mqtt::getWillTopic ( ) const

Definition at line 396 of file Mqtt.cpp.

396 {
397 return willTopic;
398 }

References willTopic.

◆ initSession() [1/2]

bool iot::mqtt::server::Mqtt::initSession ( const utils::Timeval keepAlive)
private

Definition at line 155 of file Mqtt.cpp.

155 {
156 bool success = true;
157
158 if (broker->hasActiveSession(clientId)) {
159 LOG(ERROR) << connectionName << " MQTT Broker: Existing session found for ClientId = " << clientId;
160 LOG(ERROR) << connectionName << " MQTT Broker: closing";
162
163 willFlag = false;
164 success = false;
165 } else if (broker->hasRetainedSession(clientId)) {
166 LOG(INFO) << connectionName << " MQTT Broker: Retained session found for ClientId = " << clientId;
167 if (cleanSession) {
168 LOG(DEBUG) << connectionName << " New SessionId = " << this;
170
171 broker->unsubscribe(clientId);
172 initSession(broker->newSession(clientId, this), keepAlive);
173 } else {
174 LOG(DEBUG) << connectionName << " Renew SessionId = " << this;
176
177 initSession(broker->renewSession(clientId, this), keepAlive);
178 broker->restartSession(clientId);
179 }
180 } else {
181 LOG(INFO) << connectionName << " MQTT Broker: No session found for ClientId = " << clientId;
182 LOG(INFO) << connectionName << " MQTT Broker: new SessionId = " << this;
183
185
186 initSession(broker->newSession(clientId, this), keepAlive);
187 }
188
189 return success;
190 }
#define MQTT_CONNACK_ACCEPT
Definition Connack.h:59
#define MQTT_SESSION_PRESENT
Definition Connack.h:67

References cleanSession, iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, iot::mqtt::server::broker::Broker::hasActiveSession(), iot::mqtt::server::broker::Broker::hasRetainedSession(), iot::mqtt::Mqtt::initSession(), iot::mqtt::server::broker::Broker::newSession(), iot::mqtt::server::broker::Broker::renewSession(), iot::mqtt::server::broker::Broker::restartSession(), sendConnack(), iot::mqtt::server::broker::Broker::unsubscribe(), and willFlag.

Referenced by _onConnect().

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

◆ initSession() [2/2]

void iot::mqtt::Mqtt::initSession ( Session session,
utils::Timeval  keepAlive 
)
private

Definition at line 105 of file Mqtt.cpp.

174 {
175 this->session = session;
176
177 for (const auto& [packetIdentifier, publish] : session->publishMap) {
178 LOG(INFO) << connectionName << " MQTT: PUBLISH Resend";
179
180 send(publish);
181 }
182
183 for (const uint16_t packetIdentifier : session->pubrelPacketIdentifierSet) {
184 LOG(INFO) << connectionName << " MQTT: PUBREL Resend";
185
186 send(iot::mqtt::packets::Pubrel(packetIdentifier));
187 }
188
189 if (keepAlive > 0) {
190 keepAlive *= 1.5;
191
192 LOG(INFO) << connectionName << " MQTT: Keep alive initialized with: " << keepAlive;
193
195 [this, keepAlive]() {
196 LOG(ERROR) << connectionName << " MQTT: Keep-alive timer expired. Interval was: " << keepAlive;
198 },
199 keepAlive);
200 }
201
203 }
virtual void setTimeout(const utils::Timeval &timeout)=0
static Timer singleshotTimer(const std::function< void()> &dispatcher, const utils::Timeval &timeout)
Definition Timer.cpp:57
virtual core::socket::stream::SocketConnection * getSocketConnection() const =0
virtual void close()=0
core::timer::Timer keepAliveTimer
Definition Mqtt.h:151
Session * session
Definition Mqtt.h:155
void send(const iot::mqtt::ControlPacket &controlPacket) const
Definition Mqtt.cpp:205

◆ onConnect()

void iot::mqtt::server::Mqtt::onConnect ( const iot::mqtt::packets::Connect connect)
privatevirtual

Definition at line 206 of file Mqtt.cpp.

206 {
207 }

Referenced by _onConnect().

Here is the caller graph for this function:

◆ onDisconnect()

void iot::mqtt::server::Mqtt::onDisconnect ( const iot::mqtt::packets::Disconnect disconnect)
privatevirtual

Definition at line 218 of file Mqtt.cpp.

218 {
219 }

Referenced by _onDisconnect().

Here is the caller graph for this function:

◆ onPingreq()

void iot::mqtt::server::Mqtt::onPingreq ( const iot::mqtt::packets::Pingreq pingreq)
privatevirtual

Definition at line 215 of file Mqtt.cpp.

215 {
216 }

Referenced by _onPingreq().

Here is the caller graph for this function:

◆ onSignal()

bool iot::mqtt::server::Mqtt::onSignal ( int  sig)
overrideprotectedvirtual

Implements iot::mqtt::Mqtt.

Definition at line 94 of file Mqtt.cpp.

94 {
95 willFlag = false;
96 return true;
97 }

References willFlag.

◆ onSubscribe()

void iot::mqtt::server::Mqtt::onSubscribe ( const iot::mqtt::packets::Subscribe subscribe)
privatevirtual

Definition at line 209 of file Mqtt.cpp.

209 {
210 }

Referenced by _onSubscribe().

Here is the caller graph for this function:

◆ onUnsubscribe()

void iot::mqtt::server::Mqtt::onUnsubscribe ( const iot::mqtt::packets::Unsubscribe unsubscribe)
privatevirtual

Definition at line 212 of file Mqtt.cpp.

212 {
213 }

Referenced by _onUnsubscribe().

Here is the caller graph for this function:

◆ releaseSession()

void iot::mqtt::server::Mqtt::releaseSession ( )
private

Definition at line 192 of file Mqtt.cpp.

192 {
193 if (broker->isActiveSession(clientId, this)) {
194 if (cleanSession) {
195 LOG(DEBUG) << connectionName << " MQTT Broker: Delete session for ClientId = " << clientId;
196 LOG(DEBUG) << connectionName << " MQTT Broker: SessionId = " << this;
197 broker->deleteSession(clientId);
198 } else {
199 LOG(DEBUG) << connectionName << " MQTT Broker: Retain session for ClientId = " << clientId;
200 LOG(DEBUG) << connectionName << " MQTT Broker: SessionId = " << this;
201 broker->retainSession(clientId);
202 }
203 }
204 }

References cleanSession, iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, iot::mqtt::server::broker::Broker::deleteSession(), iot::mqtt::server::broker::Broker::isActiveSession(), and iot::mqtt::server::broker::Broker::retainSession().

Referenced by _onDisconnect(), and ~Mqtt().

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

◆ sendConnack()

void iot::mqtt::server::Mqtt::sendConnack ( uint8_t  returnCode,
uint8_t  flags 
) const

Definition at line 356 of file Mqtt.cpp.

356 { // Server
357 send(iot::mqtt::packets::Connack(returnCode, flags));
358 }

References iot::mqtt::packets::Connack::Connack(), and iot::mqtt::Mqtt::send().

Referenced by _onConnect(), and initSession().

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

◆ sendPingresp()

void iot::mqtt::server::Mqtt::sendPingresp ( ) const

Definition at line 368 of file Mqtt.cpp.

References iot::mqtt::packets::Pingresp::Pingresp(), and iot::mqtt::Mqtt::send().

Referenced by _onPingreq().

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

◆ sendSuback()

void iot::mqtt::server::Mqtt::sendSuback ( uint16_t  packetIdentifier,
const std::list< uint8_t > &  returnCodes 
) const

Definition at line 360 of file Mqtt.cpp.

360 { // Server
361 send(iot::mqtt::packets::Suback(packetIdentifier, returnCodes));
362 }

References iot::mqtt::Mqtt::send(), and iot::mqtt::packets::Suback::Suback().

Referenced by _onSubscribe().

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

◆ sendUnsuback()

void iot::mqtt::server::Mqtt::sendUnsuback ( uint16_t  packetIdentifier) const

Definition at line 364 of file Mqtt.cpp.

364 { // Server
365 send(iot::mqtt::packets::Unsuback(packetIdentifier));
366 }

References iot::mqtt::Mqtt::send(), and iot::mqtt::packets::Unsuback::Unsuback().

Referenced by _onUnsubscribe().

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

◆ subscribe()

void iot::mqtt::server::Mqtt::subscribe ( const std::string &  topic,
uint8_t  qoS 
) const

Definition at line 86 of file Mqtt.cpp.

86 {
87 broker->subscribe(clientId, topic, qoS);
88 }

References iot::mqtt::Mqtt::clientId, and iot::mqtt::server::broker::Broker::subscribe().

Here is the call graph for this function:

◆ unsubscribe()

void iot::mqtt::server::Mqtt::unsubscribe ( const std::string &  topic) const

Definition at line 90 of file Mqtt.cpp.

90 {
91 broker->unsubscribe(clientId, topic);
92 }

References iot::mqtt::Mqtt::clientId, and iot::mqtt::server::broker::Broker::unsubscribe().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ iot::mqtt::server::packets::Connect

Definition at line 170 of file Mqtt.h.

◆ iot::mqtt::server::packets::Disconnect

Definition at line 174 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pingreq

Definition at line 173 of file Mqtt.h.

◆ iot::mqtt::server::packets::Puback

Definition at line 178 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pubcomp

Definition at line 176 of file Mqtt.h.

◆ iot::mqtt::server::packets::Publish

Definition at line 175 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pubrec

Definition at line 177 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pubrel

Definition at line 179 of file Mqtt.h.

◆ iot::mqtt::server::packets::Subscribe

Definition at line 171 of file Mqtt.h.

◆ iot::mqtt::server::packets::Unsubscribe

Definition at line 172 of file Mqtt.h.

Member Data Documentation

◆ broker

std::shared_ptr<iot::mqtt::server::broker::Broker> iot::mqtt::server::Mqtt::broker
protected

Definition at line 168 of file Mqtt.h.

◆ cleanSession

bool iot::mqtt::server::Mqtt::cleanSession = false
protected

Definition at line 165 of file Mqtt.h.

Referenced by _onConnect(), getCleanSession(), initSession(), and releaseSession().

◆ connectFlags

uint8_t iot::mqtt::server::Mqtt::connectFlags = 0
protected

Definition at line 152 of file Mqtt.h.

Referenced by _onConnect(), and getConnectFlags().

◆ keepAlive

uint16_t iot::mqtt::server::Mqtt::keepAlive = 0
protected

Definition at line 153 of file Mqtt.h.

Referenced by _onConnect(), and getKeepAlive().

◆ level

uint8_t iot::mqtt::server::Mqtt::level = 0
protected

Definition at line 151 of file Mqtt.h.

Referenced by _onConnect(), and getLevel().

◆ password

std::string iot::mqtt::server::Mqtt::password
protected

Definition at line 158 of file Mqtt.h.

Referenced by _onConnect(), and getPassword().

◆ passwordFlag

bool iot::mqtt::server::Mqtt::passwordFlag = false
protected

Definition at line 161 of file Mqtt.h.

Referenced by _onConnect(), and getPasswordFlag().

◆ protocol

std::string iot::mqtt::server::Mqtt::protocol
protected

Definition at line 150 of file Mqtt.h.

Referenced by _onConnect(), and getProtocol().

◆ reflect

bool iot::mqtt::server::Mqtt::reflect = true
protected

Definition at line 166 of file Mqtt.h.

Referenced by _onConnect(), and getReflect().

◆ username

std::string iot::mqtt::server::Mqtt::username
protected

Definition at line 157 of file Mqtt.h.

Referenced by _onConnect(), and getUsername().

◆ usernameFlag

bool iot::mqtt::server::Mqtt::usernameFlag = false
protected

Definition at line 160 of file Mqtt.h.

Referenced by _onConnect(), and getUsernameFlag().

◆ willFlag

bool iot::mqtt::server::Mqtt::willFlag = false
protected

Definition at line 164 of file Mqtt.h.

Referenced by _onConnect(), _onDisconnect(), getWillFlag(), initSession(), onSignal(), and ~Mqtt().

◆ willMessage

std::string iot::mqtt::server::Mqtt::willMessage
protected

Definition at line 156 of file Mqtt.h.

Referenced by _onConnect(), getWillMessage(), and ~Mqtt().

◆ willQoS

uint8_t iot::mqtt::server::Mqtt::willQoS = 0
protected

Definition at line 163 of file Mqtt.h.

Referenced by _onConnect(), getWillQoS(), and ~Mqtt().

◆ willRetain

bool iot::mqtt::server::Mqtt::willRetain = false
protected

Definition at line 162 of file Mqtt.h.

Referenced by _onConnect(), getWillRetain(), and ~Mqtt().

◆ willTopic

std::string iot::mqtt::server::Mqtt::willTopic
protected

Definition at line 155 of file Mqtt.h.

Referenced by _onConnect(), getWillTopic(), and ~Mqtt().


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