SNode.C
Loading...
Searching...
No Matches
iot::mqtt::SubProtocol< WSSubProtocolRoleT > Class Template Reference

#include <SubProtocol.h>

Inheritance diagram for iot::mqtt::SubProtocol< WSSubProtocolRoleT >:
Collaboration diagram for iot::mqtt::SubProtocol< WSSubProtocolRoleT >:

Public Member Functions

 SubProtocol (web::websocket::SubProtocolContext *subProtocolContext, const std::string &name, iot::mqtt::Mqtt *mqtt)
 ~SubProtocol () override=default
std::size_t recv (char *chunk, std::size_t chunklen) override
void send (const char *chunk, std::size_t chunklen) override
void end () override
void close () override

Private Types

using WSSubProtocolRole = WSSubProtocolRoleT

Private Member Functions

void onConnected () override
void onMessageStart (int opCode) override
void onMessageData (const char *chunk, std::size_t chunkLen) override
void onMessageEnd () override
void onMessageError (uint16_t errnum) override
void onDisconnected () override
bool onSignal (int sig) override
core::socket::stream::SocketConnectiongetSocketConnection () const override
Private Member Functions inherited from iot::mqtt::MqttContext
 MqttContext (Mqtt *mqtt)
 MqttContext (const MqttContext &)=default
MqttContextoperator= (const MqttContext &)=default
virtual ~MqttContext ()
void onConnected ()
std::size_t onReceivedFromPeer ()
void onDisconnected ()
bool onSignal (int sig)

Private Attributes

OnReceivedFromPeerEvent onReceivedFromPeerEvent
std::string data
std::vector< char > buffer
std::size_t cursor = 0
std::size_t size = 0
Private Attributes inherited from iot::mqtt::MqttContext
Mqttmqtt

Detailed Description

template<typename WSSubProtocolRoleT>
class iot::mqtt::SubProtocol< WSSubProtocolRoleT >

Definition at line 83 of file SubProtocol.h.

Member Typedef Documentation

◆ WSSubProtocolRole

template<typename WSSubProtocolRoleT>
using iot::mqtt::SubProtocol< WSSubProtocolRoleT >::WSSubProtocolRole = WSSubProtocolRoleT
private

Definition at line 87 of file SubProtocol.h.

Constructor & Destructor Documentation

◆ SubProtocol()

template<typename WSSubProtocolRole>
iot::mqtt::SubProtocol< WSSubProtocolRole >::SubProtocol ( web::websocket::SubProtocolContext * subProtocolContext,
const std::string & name,
iot::mqtt::Mqtt * mqtt )

Definition at line 59 of file SubProtocol.hpp.

66
67 if (size > 0) {
69 } else {
70 buffer.clear();
71 cursor = 0;
72 }
73 }) {
74 }
std::size_t onReceivedFromPeer()
WSSubProtocolRoleT WSSubProtocolRole
Definition SubProtocol.h:87
std::vector< char > buffer
OnReceivedFromPeerEvent onReceivedFromPeerEvent

References buffer, cursor, iot::mqtt::MqttContext::onReceivedFromPeer(), onReceivedFromPeerEvent, size, and core::EventReceiver::span().

Here is the call graph for this function:

◆ ~SubProtocol()

template<typename WSSubProtocolRoleT>
iot::mqtt::SubProtocol< WSSubProtocolRoleT >::~SubProtocol ( )
overridedefault

Member Function Documentation

◆ close()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::close ( )
overridevirtual

Implements iot::mqtt::MqttContext.

Definition at line 99 of file SubProtocol.hpp.

99 {
100 const std::string reason = "Protocol error";
101
103 }

Referenced by onMessageStart().

Here is the caller graph for this function:

◆ end()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::end ( )
overridevirtual

Implements iot::mqtt::MqttContext.

Definition at line 94 of file SubProtocol.hpp.

◆ getSocketConnection()

template<typename WSSubProtocolRole>
core::socket::stream::SocketConnection * iot::mqtt::SubProtocol< WSSubProtocolRole >::getSocketConnection ( ) const
overrideprivatevirtual

Implements iot::mqtt::MqttContext.

Definition at line 168 of file SubProtocol.hpp.

168 {
170 }
core::socket::stream::SocketConnection * getSocketConnection() const override

Referenced by onConnected(), onDisconnected(), onMessageData(), onMessageEnd(), onMessageError(), onMessageStart(), and onSignal().

Here is the caller graph for this function:

◆ onConnected()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::onConnected ( )
overrideprivate

Definition at line 106 of file SubProtocol.hpp.

106 {
107 LOG(INFO) << getSocketConnection()->getConnectionName() << " WsMqtt: connected:";
109 }
const std::string & getConnectionName() const

References getSocketConnection(), and iot::mqtt::MqttContext::onConnected().

Here is the call graph for this function:

◆ onDisconnected()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::onDisconnected ( )
overrideprivate

Definition at line 151 of file SubProtocol.hpp.

151 {
153 LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: disconnected";
154 }

References getSocketConnection(), and iot::mqtt::MqttContext::onDisconnected().

Here is the call graph for this function:

◆ onMessageData()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::onMessageData ( const char * chunk,
std::size_t chunkLen )
overrideprivate

Definition at line 122 of file SubProtocol.hpp.

122 {
123 data.append(std::string(chunk, chunkLen));
124
125 LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: Frame Data:\n"
126 << std::string(32, ' ').append(utils::hexDump(std::vector<char>(chunk, chunk + chunkLen), 32));
127 }

References data, getSocketConnection(), and utils::hexDump().

Here is the call graph for this function:

◆ onMessageEnd()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::onMessageEnd ( )
overrideprivate

Definition at line 130 of file SubProtocol.hpp.

130 {
131 LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: Message END";
132
133 buffer.insert(buffer.end(), data.begin(), data.end());
134 size += data.size();
135 data.clear();
136
137 if (size > 0) {
139 } else {
140 buffer.clear();
141 cursor = 0;
142 }
143 }

References buffer, cursor, data, getSocketConnection(), onReceivedFromPeerEvent, size, and core::EventReceiver::span().

Here is the call graph for this function:

◆ onMessageError()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::onMessageError ( uint16_t errnum)
overrideprivate

Definition at line 146 of file SubProtocol.hpp.

146 {
147 LOG(ERROR) << getSocketConnection()->getConnectionName() << " WsMqtt: Message error: " << errnum;
148 }

References getSocketConnection().

Here is the call graph for this function:

◆ onMessageStart()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::onMessageStart ( int opCode)
overrideprivate

Definition at line 112 of file SubProtocol.hpp.

112 {
114 LOG(ERROR) << getSocketConnection()->getConnectionName() << " WsMqtt: Wrong Opcode: " << opCode << " (TEXT)";
115 this->close();
116 } else {
117 LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: Message START: " << opCode << " (BIN)";
118 }
119 }
void close() override

References close(), getSocketConnection(), and web::websocket::SubProtocolContext::TEXT.

Here is the call graph for this function:

◆ onSignal()

template<typename WSSubProtocolRole>
bool iot::mqtt::SubProtocol< WSSubProtocolRole >::onSignal ( int sig)
overrideprivate

Definition at line 157 of file SubProtocol.hpp.

157 {
159 LOG(INFO) << getSocketConnection()->getConnectionName() << " WsMqtt: exit due to '" << strsignal(sig) << "' (SIG"
160 << utils::system::sigabbrev_np(sig) << " = " << sig << ")";
161
162 this->sendClose();
163
164 return ret;
165 }
std::string sigabbrev_np(int sig)
Definition signal.cpp:59

References getSocketConnection(), iot::mqtt::MqttContext::onSignal(), and utils::system::sigabbrev_np().

Here is the call graph for this function:

◆ recv()

template<typename WSSubProtocolRole>
std::size_t iot::mqtt::SubProtocol< WSSubProtocolRole >::recv ( char * chunk,
std::size_t chunklen )
overridevirtual

Implements iot::mqtt::MqttContext.

Definition at line 77 of file SubProtocol.hpp.

77 {
79
80 std::copy(buffer.data() + cursor, buffer.data() + cursor + maxReturn, chunk);
81
83 size -= maxReturn;
84
85 return maxReturn;
86 }

References buffer, cursor, and size.

◆ send()

template<typename WSSubProtocolRole>
void iot::mqtt::SubProtocol< WSSubProtocolRole >::send ( const char * chunk,
std::size_t chunklen )
overridevirtual

Implements iot::mqtt::MqttContext.

Definition at line 89 of file SubProtocol.hpp.

Member Data Documentation

◆ buffer

template<typename WSSubProtocolRoleT>
std::vector<char> iot::mqtt::SubProtocol< WSSubProtocolRoleT >::buffer
private

Definition at line 113 of file SubProtocol.h.

Referenced by onMessageEnd(), recv(), and SubProtocol().

◆ cursor

template<typename WSSubProtocolRoleT>
std::size_t iot::mqtt::SubProtocol< WSSubProtocolRoleT >::cursor = 0
private

Definition at line 114 of file SubProtocol.h.

Referenced by onMessageEnd(), recv(), and SubProtocol().

◆ data

template<typename WSSubProtocolRoleT>
std::string iot::mqtt::SubProtocol< WSSubProtocolRoleT >::data
private

Definition at line 112 of file SubProtocol.h.

Referenced by onMessageData(), and onMessageEnd().

◆ onReceivedFromPeerEvent

template<typename WSSubProtocolRoleT>
OnReceivedFromPeerEvent iot::mqtt::SubProtocol< WSSubProtocolRoleT >::onReceivedFromPeerEvent
private

Definition at line 110 of file SubProtocol.h.

Referenced by onMessageEnd(), and SubProtocol().

◆ size

template<typename WSSubProtocolRoleT>
std::size_t iot::mqtt::SubProtocol< WSSubProtocolRoleT >::size = 0
private

Definition at line 115 of file SubProtocol.h.

Referenced by onMessageEnd(), recv(), and SubProtocol().


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