SNode.C
|
#include <Mqtt.h>
Public Member Functions | |
Mqtt (const std::string &connectionName) | |
Mqtt (const std::string &connectionName, const std::string &clientId) | |
Mqtt (Mqtt &&)=delete | |
Mqtt (const Mqtt &)=delete | |
Mqtt & | operator= (Mqtt &&)=delete |
Mqtt & | operator= (const Mqtt &)=delete |
virtual | ~Mqtt () |
virtual void | onConnected () |
virtual void | onDisconnected () |
virtual bool | onSignal (int sig)=0 |
const std::string & | getConnectionName () const |
const MqttContext * | getMqttContext () 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 |
Static Public Member Functions | |
static std::string | toHexString (const std::vector< char > &data) |
static std::string | toHexString (const std::string &data) |
Protected Member Functions | |
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 | connectionName |
std::string | clientId |
MqttContext * | mqttContext = nullptr |
Private Member Functions | |
std::size_t | onReceivedFromPeer () |
void | setMqttContext (MqttContext *mqttContext) |
virtual iot::mqtt::ControlPacketDeserializer * | createControlPacketDeserializer (iot::mqtt::FixedHeader &staticHeader)=0 |
virtual void | deliverPacket (iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer)=0 |
void | send (const std::vector< char > &data) const |
Private Attributes | |
iot::mqtt::FixedHeader | fixedHeader |
iot::mqtt::ControlPacketDeserializer * | controlPacketDeserializer = nullptr |
uint16_t | _packetIdentifier = 0 |
core::timer::Timer | keepAliveTimer |
int | state = 0 |
Session * | session = nullptr |
Friends | |
class | MqttContext |
iot::mqtt::Mqtt::Mqtt | ( | const std::string & | connectionName | ) |
Definition at line 69 of file Mqtt.cpp.
References connectionName.
Referenced by iot::mqtt::server::Mqtt::Mqtt().
iot::mqtt::Mqtt::Mqtt | ( | const std::string & | connectionName, |
const std::string & | clientId | ||
) |
Definition at line 73 of file Mqtt.cpp.
References clientId, and connectionName.
Referenced by iot::mqtt::client::Mqtt::Mqtt().
|
delete |
|
delete |
|
virtual |
Reimplemented in iot::mqtt::client::Mqtt, and iot::mqtt::server::Mqtt.
Definition at line 78 of file Mqtt.cpp.
References core::Timer::cancel(), controlPacketDeserializer, and keepAliveTimer.
|
protected |
Definition at line 308 of file Mqtt.cpp.
References connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Puback::getPacketIdentifier(), mqttContext, and onPuback().
Referenced by iot::mqtt::client::packets::Puback::deliverPacket(), and iot::mqtt::server::packets::Puback::deliverPacket().
|
protected |
Definition at line 353 of file Mqtt.cpp.
References connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Pubcomp::getPacketIdentifier(), mqttContext, onPubcomp(), iot::mqtt::Session::publishMap, iot::mqtt::Session::pubrelPacketIdentifierSet, and session.
Referenced by iot::mqtt::client::packets::Pubcomp::deliverPacket(), and iot::mqtt::server::packets::Pubcomp::deliverPacket().
|
protected |
Definition at line 268 of file Mqtt.cpp.
References connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Publish::getDup(), iot::mqtt::packets::Publish::getMessage(), iot::mqtt::packets::Publish::getPacketIdentifier(), iot::mqtt::packets::Publish::getQoS(), iot::mqtt::packets::Publish::getRetain(), iot::mqtt::packets::Publish::getTopic(), mqttContext, iot::mqtt::Session::publishPacketIdentifierSet, sendPuback(), sendPubrec(), session, and toHexString().
Referenced by iot::mqtt::client::Mqtt::_onPublish(), and iot::mqtt::server::Mqtt::_onPublish().
|
protected |
Definition at line 320 of file Mqtt.cpp.
References connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Pubrec::getPacketIdentifier(), mqttContext, onPubrec(), iot::mqtt::Session::publishMap, iot::mqtt::Session::pubrelPacketIdentifierSet, sendPubrel(), and session.
Referenced by iot::mqtt::client::packets::Pubrec::deliverPacket(), and iot::mqtt::server::packets::Pubrec::deliverPacket().
|
protected |
Definition at line 337 of file Mqtt.cpp.
References connectionName, iot::mqtt::MqttContext::end(), iot::mqtt::packets::Pubrel::getPacketIdentifier(), mqttContext, onPubrel(), iot::mqtt::Session::publishPacketIdentifierSet, sendPubcomp(), and session.
Referenced by iot::mqtt::client::packets::Pubrel::deliverPacket(), and iot::mqtt::server::packets::Pubrel::deliverPacket().
|
privatepure virtual |
Implemented in iot::mqtt::client::Mqtt, and iot::mqtt::server::Mqtt.
|
privatepure virtual |
Implemented in iot::mqtt::client::Mqtt, and iot::mqtt::server::Mqtt.
const std::string & iot::mqtt::Mqtt::getConnectionName | ( | ) | const |
Definition at line 170 of file Mqtt.cpp.
References connectionName.
const MqttContext * iot::mqtt::Mqtt::getMqttContext | ( | ) | const |
|
protected |
Definition at line 398 of file Mqtt.cpp.
References _packetIdentifier.
Referenced by sendPublish(), iot::mqtt::client::Mqtt::sendSubscribe(), and iot::mqtt::client::Mqtt::sendUnsubscribe().
|
protected |
Definition at line 174 of file Mqtt.cpp.
References iot::mqtt::MqttContext::close(), connectionName, iot::mqtt::MqttContext::getSocketConnection(), keepAliveTimer, mqttContext, utils::Timeval::operator*=(), core::timer::Timer::operator=(), utils::Timeval::operator>(), iot::mqtt::Session::publishMap, iot::mqtt::packets::Pubrel::Pubrel(), iot::mqtt::Session::pubrelPacketIdentifierSet, send(), session, core::socket::stream::SocketConnection::setTimeout(), and core::timer::Timer::singleshotTimer().
Referenced by iot::mqtt::client::Mqtt::_onConnack(), and iot::mqtt::server::Mqtt::initSession().
|
virtual |
Definition at line 95 of file Mqtt.cpp.
Referenced by iot::mqtt::MqttContext::onConnected().
|
virtual |
Definition at line 166 of file Mqtt.cpp.
References connectionName.
Referenced by iot::mqtt::MqttContext::onDisconnected().
|
protectedvirtual |
Definition at line 256 of file Mqtt.cpp.
Referenced by _onPuback().
|
protectedvirtual |
Definition at line 265 of file Mqtt.cpp.
Referenced by _onPubcomp().
|
protectedvirtual |
Definition at line 253 of file Mqtt.cpp.
Referenced by iot::mqtt::client::Mqtt::_onPublish(), and iot::mqtt::server::Mqtt::_onPublish().
|
protectedvirtual |
Definition at line 259 of file Mqtt.cpp.
Referenced by _onPubrec().
|
protectedvirtual |
Definition at line 262 of file Mqtt.cpp.
Referenced by _onPubrel().
|
private |
Definition at line 99 of file Mqtt.cpp.
References iot::mqtt::FixedHeader::deserialize(), fixedHeader, mqttContext, and state.
Referenced by iot::mqtt::MqttContext::onReceivedFromPeer().
|
pure virtual |
Implemented in iot::mqtt::client::Mqtt, and iot::mqtt::server::Mqtt.
Referenced by iot::mqtt::MqttContext::onSignal().
|
protected |
Definition at line 377 of file Mqtt.cpp.
References connectionName, iot::mqtt::FixedHeader::getFlags(), iot::mqtt::FixedHeader::getRemainingLength(), iot::mqtt::FixedHeader::getType(), iot::mqtt::mqttPackageName, iot::mqtt::FixedHeader::serialize(), and toHexString().
|
protected |
Definition at line 368 of file Mqtt.cpp.
References clientId, connectionName, iot::mqtt::ControlPacket::getName(), iot::mqtt::ControlPacket::serializeVP(), and toHexString().
Referenced by iot::mqtt::client::packets::Connack::deliverPacket(), iot::mqtt::client::packets::Pingresp::deliverPacket(), iot::mqtt::client::packets::Puback::deliverPacket(), iot::mqtt::client::packets::Pubcomp::deliverPacket(), iot::mqtt::client::packets::Publish::deliverPacket(), iot::mqtt::client::packets::Pubrec::deliverPacket(), iot::mqtt::client::packets::Pubrel::deliverPacket(), iot::mqtt::client::packets::Suback::deliverPacket(), iot::mqtt::client::packets::Unsuback::deliverPacket(), iot::mqtt::server::packets::Connect::deliverPacket(), iot::mqtt::server::packets::Disconnect::deliverPacket(), iot::mqtt::server::packets::Pingreq::deliverPacket(), iot::mqtt::server::packets::Puback::deliverPacket(), iot::mqtt::server::packets::Pubcomp::deliverPacket(), iot::mqtt::server::packets::Publish::deliverPacket(), iot::mqtt::server::packets::Pubrec::deliverPacket(), iot::mqtt::server::packets::Pubrel::deliverPacket(), iot::mqtt::server::packets::Subscribe::deliverPacket(), and iot::mqtt::server::packets::Unsubscribe::deliverPacket().
|
protected |
Definition at line 205 of file Mqtt.cpp.
References clientId, connectionName, iot::mqtt::ControlPacket::getName(), send(), and iot::mqtt::ControlPacket::serialize().
Referenced by initSession(), iot::mqtt::server::Mqtt::sendConnack(), iot::mqtt::client::Mqtt::sendConnect(), iot::mqtt::client::Mqtt::sendDisconnect(), iot::mqtt::client::Mqtt::sendPingreq(), iot::mqtt::server::Mqtt::sendPingresp(), sendPuback(), sendPubcomp(), sendPublish(), sendPubrec(), sendPubrel(), iot::mqtt::server::Mqtt::sendSuback(), iot::mqtt::client::Mqtt::sendSubscribe(), iot::mqtt::server::Mqtt::sendUnsuback(), and iot::mqtt::client::Mqtt::sendUnsubscribe().
|
private |
Definition at line 211 of file Mqtt.cpp.
References connectionName, mqttContext, iot::mqtt::MqttContext::send(), and toHexString().
Referenced by send().
void iot::mqtt::Mqtt::sendPuback | ( | uint16_t | packetIdentifier | ) | const |
Definition at line 237 of file Mqtt.cpp.
References iot::mqtt::packets::Puback::Puback(), and send().
Referenced by _onPublish().
void iot::mqtt::Mqtt::sendPubcomp | ( | uint16_t | packetIdentifier | ) | const |
Definition at line 249 of file Mqtt.cpp.
References iot::mqtt::packets::Pubcomp::Pubcomp(), and send().
Referenced by _onPubrel().
void iot::mqtt::Mqtt::sendPublish | ( | const std::string & | topic, |
const std::string & | message, | ||
uint8_t | qoS, | ||
bool | retain | ||
) |
Definition at line 217 of file Mqtt.cpp.
References _packetIdentifier, connectionName, getPacketIdentifier(), iot::mqtt::packets::Publish::Publish(), iot::mqtt::Session::publishMap, send(), session, and toHexString().
Referenced by iot::mqtt::server::broker::Session::sendPublish().
void iot::mqtt::Mqtt::sendPubrec | ( | uint16_t | packetIdentifier | ) | const |
Definition at line 241 of file Mqtt.cpp.
References iot::mqtt::packets::Pubrec::Pubrec(), and send().
Referenced by _onPublish().
void iot::mqtt::Mqtt::sendPubrel | ( | uint16_t | packetIdentifier | ) | const |
Definition at line 245 of file Mqtt.cpp.
References iot::mqtt::packets::Pubrel::Pubrel(), and send().
Referenced by _onPubrec().
|
private |
Definition at line 87 of file Mqtt.cpp.
References mqttContext.
Referenced by iot::mqtt::MqttContext::MqttContext().
|
static |
Definition at line 394 of file Mqtt.cpp.
References toHexString().
Referenced by _onPublish(), iot::mqtt::server::broker::RetainTree::TopicLevel::appear(), iot::mqtt::server::broker::RetainTree::TopicLevel::appear(), iot::mqtt::server::broker::SubscribtionTree::TopicLevel::publish(), iot::mqtt::server::broker::RetainTree::TopicLevel::retain(), sendPublish(), and iot::mqtt::server::broker::Session::sendPublish().
|
static |
Definition at line 389 of file Mqtt.cpp.
References utils::hexDump().
Referenced by printFixedHeader(), printVP(), send(), and toHexString().
|
friend |
|
private |
Definition at line 149 of file Mqtt.h.
Referenced by getPacketIdentifier(), and sendPublish().
|
protected |
Definition at line 143 of file Mqtt.h.
Referenced by iot::mqtt::server::Mqtt::_onConnect(), iot::mqtt::server::Mqtt::_onPublish(), iot::mqtt::server::Mqtt::_onSubscribe(), iot::mqtt::server::Mqtt::_onUnsubscribe(), iot::mqtt::server::Mqtt::getClientId(), iot::mqtt::server::Mqtt::getSubscriptions(), iot::mqtt::server::Mqtt::initSession(), Mqtt(), printVP(), iot::mqtt::server::Mqtt::releaseSession(), send(), iot::mqtt::client::Mqtt::sendConnect(), iot::mqtt::server::Mqtt::subscribe(), iot::mqtt::server::Mqtt::unsubscribe(), and iot::mqtt::server::Mqtt::~Mqtt().
|
protected |
Definition at line 142 of file Mqtt.h.
Referenced by iot::mqtt::client::Mqtt::_onConnack(), iot::mqtt::server::Mqtt::_onConnect(), _onPuback(), _onPubcomp(), _onPublish(), _onPubrec(), _onPubrel(), iot::mqtt::client::Mqtt::_onSuback(), iot::mqtt::server::Mqtt::_onSubscribe(), iot::mqtt::client::Mqtt::_onUnsuback(), iot::mqtt::server::Mqtt::_onUnsubscribe(), getConnectionName(), iot::mqtt::server::Mqtt::initSession(), initSession(), Mqtt(), Mqtt(), onDisconnected(), printFixedHeader(), printVP(), iot::mqtt::server::Mqtt::releaseSession(), send(), send(), iot::mqtt::client::Mqtt::sendConnect(), sendPublish(), and iot::mqtt::client::Mqtt::~Mqtt().
|
private |
|
private |
Definition at line 146 of file Mqtt.h.
Referenced by onReceivedFromPeer().
|
private |
Definition at line 151 of file Mqtt.h.
Referenced by initSession(), and ~Mqtt().
|
protected |
Definition at line 158 of file Mqtt.h.
Referenced by iot::mqtt::server::Mqtt::_onConnect(), _onPuback(), _onPubcomp(), _onPublish(), _onPubrec(), _onPubrel(), iot::mqtt::client::Mqtt::_onSuback(), iot::mqtt::server::Mqtt::_onSubscribe(), iot::mqtt::client::Mqtt::_onUnsuback(), iot::mqtt::server::Mqtt::_onUnsubscribe(), getMqttContext(), initSession(), onReceivedFromPeer(), send(), iot::mqtt::client::Mqtt::sendDisconnect(), and setMqttContext().
|
private |
Definition at line 155 of file Mqtt.h.
Referenced by _onPubcomp(), _onPublish(), _onPubrec(), _onPubrel(), initSession(), and sendPublish().
|
private |
Definition at line 153 of file Mqtt.h.
Referenced by onReceivedFromPeer().