SNode.C
Loading...
Searching...
No Matches
iot::mqtt_fast::SocketContext Class Referenceabstract

#include <SocketContext.h>

Inheritance diagram for iot::mqtt_fast::SocketContext:
Collaboration diagram for iot::mqtt_fast::SocketContext:

Public Member Functions

 SocketContext (core::socket::stream::SocketConnection *socketConnection)
 
void sendConnect (const std::string &clientId)
 
void sendConnack (uint8_t returnCode, uint8_t flags)
 
void sendPublish (const std::string &topic, const std::string &message, bool dup=false, uint8_t qoS=0, bool retain=false)
 
void sendPuback (uint16_t packetIdentifier)
 
void sendPubrec (uint16_t packetIdentifier)
 
void sendPubrel (uint16_t packetIdentifier)
 
void sendPubcomp (uint16_t packetIdentifier)
 
void sendSubscribe (std::list< Topic > &topics)
 
void sendSuback (uint16_t packetIdentifier, const std::list< uint8_t > &returnCodes)
 
void sendUnsubscribe (const std::list< std::string > &topics)
 
void sendUnsuback (uint16_t packetIdentifier)
 
void sendPingreq ()
 
void sendPingresp ()
 
void sendDisconnect ()
 
- Public Member Functions inherited from core::socket::stream::SocketContext
 SocketContext (core::socket::stream::SocketConnection *socketConnection)
 
void sendToPeer (const char *chunk, std::size_t chunkLen) const final
 
bool streamToPeer (core::pipe::Source *source) const
 
void streamEof ()
 
std::size_t readFromPeer (char *chunk, std::size_t chunklen) const final
 
void setTimeout (const utils::Timeval &timeout) final
 
void shutdownRead ()
 
void shutdownWrite (bool forceClose=false)
 
void close () override
 
SocketConnectiongetSocketConnection () const
 
virtual void switchSocketContext (SocketContext *newSocketContext)
 
void sendToPeer (const std::string &data) const
 
- Public Member Functions inherited from core::socket::SocketContext
 SocketContext (const SocketContext &)=delete
 
 SocketContext (SocketContext &&)=delete
 
SocketContextoperator= (const SocketContext &)=delete
 
SocketContextoperator= (SocketContext &&)=delete
 
void sendToPeer (const std::string &data) const
 

Private Member Functions

virtual void onConnect (const iot::mqtt_fast::packets::Connect &connect)=0
 
virtual void onConnack (const iot::mqtt_fast::packets::Connack &connack)=0
 
virtual void onPublish (const iot::mqtt_fast::packets::Publish &publish)=0
 
virtual void onPuback (const iot::mqtt_fast::packets::Puback &puback)=0
 
virtual void onPubrec (const iot::mqtt_fast::packets::Pubrec &pubrec)=0
 
virtual void onPubrel (const iot::mqtt_fast::packets::Pubrel &pubrel)=0
 
virtual void onPubcomp (const iot::mqtt_fast::packets::Pubcomp &pubcomp)=0
 
virtual void onSubscribe (const iot::mqtt_fast::packets::Subscribe &subscribe)=0
 
virtual void onSuback (const iot::mqtt_fast::packets::Suback &suback)=0
 
virtual void onUnsubscribe (const iot::mqtt_fast::packets::Unsubscribe &unsubscribe)=0
 
virtual void onUnsuback (const iot::mqtt_fast::packets::Unsuback &unsuback)=0
 
virtual void onPingreq (const iot::mqtt_fast::packets::Pingreq &pingreq)=0
 
virtual void onPingresp (const iot::mqtt_fast::packets::Pingresp &pingresp)=0
 
virtual void onDisconnect (const iot::mqtt_fast::packets::Disconnect &disconnect)=0
 
std::size_t onReceivedFromPeer () final
 
void send (iot::mqtt_fast::ControlPacket &&controlPacket) const
 
void send (iot::mqtt_fast::ControlPacket &controlPacket) const
 
void send (std::vector< char > &&data) const
 
uint16_t getPacketIdentifier ()
 

Static Private Member Functions

static void printData (const std::vector< char > &data)
 

Private Attributes

iot::mqtt_fast::ControlPacketFactory controlPacketFactory
 
uint16_t _packetIdentifier = 0
 

Additional Inherited Members

- Protected Member Functions inherited from core::socket::stream::SocketContext
void onWriteError (int errnum) override
 
void onReadError (int errnum) override
 
- Protected Member Functions inherited from core::socket::SocketContext
 SocketContext ()=default
 
virtual ~SocketContext ()
 
virtual bool onSignal (int sig)=0
 

Detailed Description

Definition at line 61 of file SocketContext.h.

Constructor & Destructor Documentation

◆ SocketContext()

iot::mqtt_fast::SocketContext::SocketContext ( core::socket::stream::SocketConnection * socketConnection)
explicit

Definition at line 37 of file SocketContext.cpp.

39 , controlPacketFactory(this) {
40 }
core::socket::stream::SocketConnection * socketConnection
iot::mqtt_fast::ControlPacketFactory controlPacketFactory

Member Function Documentation

◆ getPacketIdentifier()

uint16_t iot::mqtt_fast::SocketContext::getPacketIdentifier ( )
inlineprivate

Definition at line 103 of file SocketContext.h.

103 {
105
106 if (_packetIdentifier == 0) {
108 }
109
110 return _packetIdentifier;
111 }

References _packetIdentifier.

◆ onConnack()

virtual void iot::mqtt_fast::SocketContext::onConnack ( const iot::mqtt_fast::packets::Connack & connack)
privatepure virtual

◆ onConnect()

virtual void iot::mqtt_fast::SocketContext::onConnect ( const iot::mqtt_fast::packets::Connect & connect)
privatepure virtual

◆ onDisconnect()

virtual void iot::mqtt_fast::SocketContext::onDisconnect ( const iot::mqtt_fast::packets::Disconnect & disconnect)
privatepure virtual

◆ onPingreq()

virtual void iot::mqtt_fast::SocketContext::onPingreq ( const iot::mqtt_fast::packets::Pingreq & pingreq)
privatepure virtual

◆ onPingresp()

virtual void iot::mqtt_fast::SocketContext::onPingresp ( const iot::mqtt_fast::packets::Pingresp & pingresp)
privatepure virtual

◆ onPuback()

virtual void iot::mqtt_fast::SocketContext::onPuback ( const iot::mqtt_fast::packets::Puback & puback)
privatepure virtual

◆ onPubcomp()

virtual void iot::mqtt_fast::SocketContext::onPubcomp ( const iot::mqtt_fast::packets::Pubcomp & pubcomp)
privatepure virtual

◆ onPublish()

virtual void iot::mqtt_fast::SocketContext::onPublish ( const iot::mqtt_fast::packets::Publish & publish)
privatepure virtual

◆ onPubrec()

virtual void iot::mqtt_fast::SocketContext::onPubrec ( const iot::mqtt_fast::packets::Pubrec & pubrec)
privatepure virtual

◆ onPubrel()

virtual void iot::mqtt_fast::SocketContext::onPubrel ( const iot::mqtt_fast::packets::Pubrel & pubrel)
privatepure virtual

◆ onReceivedFromPeer()

std::size_t iot::mqtt_fast::SocketContext::onReceivedFromPeer ( )
finalprivatevirtual

Implements core::socket::SocketContext.

Definition at line 140 of file SocketContext.cpp.

140 {
141 const std::size_t consumed = controlPacketFactory.construct();
142
144 LOG(ERROR) << "MQTT (fast): SocketContext: Error during ControlPacket construction";
145 close();
146 } else if (controlPacketFactory.isComplete()) {
147 LOG(DEBUG) << "MQTT (fast): ======================================================";
148 LOG(DEBUG) << "MQTT (fast): PacketType: " << static_cast<uint16_t>(controlPacketFactory.getPacketType());
149 LOG(DEBUG) << "MQTT (fast): PacketFlags: " << static_cast<uint16_t>(controlPacketFactory.getPacketFlags());
150 LOG(DEBUG) << "MQTT (fast): RemainingLength: " << static_cast<uint16_t>(controlPacketFactory.getRemainingLength());
151
153
155 case MQTT_CONNECT:
157 break;
158 case MQTT_CONNACK:
160 break;
161 case MQTT_PUBLISH:
163 break;
164 case MQTT_PUBACK:
166 break;
167 case MQTT_PUBREC:
169 break;
170 case MQTT_PUBREL:
172 break;
173 case MQTT_PUBCOMP:
175 break;
176 case MQTT_SUBSCRIBE:
178 break;
179 case MQTT_SUBACK:
181 break;
182 case MQTT_UNSUBSCRIBE:
184 break;
185 case MQTT_UNSUBACK:
187 break;
188 case MQTT_PINGREQ:
190 break;
191 case MQTT_PINGRESP:
193 break;
194 case MQTT_DISCONNECT:
196 break;
197 default:
198 close();
199 break;
200 }
201
203 }
204
205 return consumed;
206 }
iot::mqtt_fast::types::Binary & getPacket()
virtual void onPubrel(const iot::mqtt_fast::packets::Pubrel &pubrel)=0
virtual void onSuback(const iot::mqtt_fast::packets::Suback &suback)=0
virtual void onPingresp(const iot::mqtt_fast::packets::Pingresp &pingresp)=0
virtual void onPubcomp(const iot::mqtt_fast::packets::Pubcomp &pubcomp)=0
virtual void onDisconnect(const iot::mqtt_fast::packets::Disconnect &disconnect)=0
virtual void onConnect(const iot::mqtt_fast::packets::Connect &connect)=0
virtual void onPuback(const iot::mqtt_fast::packets::Puback &puback)=0
virtual void onUnsuback(const iot::mqtt_fast::packets::Unsuback &unsuback)=0
virtual void onSubscribe(const iot::mqtt_fast::packets::Subscribe &subscribe)=0
virtual void onConnack(const iot::mqtt_fast::packets::Connack &connack)=0
static void printData(const std::vector< char > &data)
virtual void onUnsubscribe(const iot::mqtt_fast::packets::Unsubscribe &unsubscribe)=0
virtual void onPubrec(const iot::mqtt_fast::packets::Pubrec &pubrec)=0
virtual void onPublish(const iot::mqtt_fast::packets::Publish &publish)=0
virtual void onPingreq(const iot::mqtt_fast::packets::Pingreq &pingreq)=0
std::vector< char > & getValue()
Definition Binary.cpp:54
#define MQTT_CONNACK
Definition Connack.h:35
#define MQTT_CONNECT
Definition Connect.h:36
#define MQTT_DISCONNECT
Definition Disconnect.h:33
#define MQTT_PINGREQ
Definition Pingreq.h:33
#define MQTT_PINGRESP
Definition Pingresp.h:33
#define MQTT_PUBACK
Definition Puback.h:35
#define MQTT_PUBCOMP
Definition Pubcomp.h:35
#define MQTT_PUBLISH
Definition Publish.h:36
#define MQTT_PUBREC
Definition Pubrec.h:35
#define MQTT_PUBREL
Definition Pubrel.h:35
#define MQTT_SUBACK
Definition Suback.h:36
#define MQTT_SUBSCRIBE
Definition Subscribe.h:37
#define MQTT_UNSUBACK
Definition Unsuback.h:35
#define MQTT_UNSUBSCRIBE
Definition Unsubscribe.h:37

◆ onSuback()

virtual void iot::mqtt_fast::SocketContext::onSuback ( const iot::mqtt_fast::packets::Suback & suback)
privatepure virtual

◆ onSubscribe()

virtual void iot::mqtt_fast::SocketContext::onSubscribe ( const iot::mqtt_fast::packets::Subscribe & subscribe)
privatepure virtual

◆ onUnsuback()

virtual void iot::mqtt_fast::SocketContext::onUnsuback ( const iot::mqtt_fast::packets::Unsuback & unsuback)
privatepure virtual

◆ onUnsubscribe()

virtual void iot::mqtt_fast::SocketContext::onUnsubscribe ( const iot::mqtt_fast::packets::Unsubscribe & unsubscribe)
privatepure virtual

◆ printData()

void iot::mqtt_fast::SocketContext::printData ( const std::vector< char > & data)
staticprivate

Definition at line 221 of file SocketContext.cpp.

221 {
222 std::stringstream ss;
223
224 ss << "Data: ";
225 unsigned long i = 0;
226 for (char const ch : data) {
227 if (i != 0 && i % 8 == 0 && i + 1 != data.size()) {
228 ss << std::endl;
229 ss << " ";
230 }
231 ++i;
232 ss << "0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<uint16_t>(static_cast<uint8_t>(ch))
233 << " "; // << " | ";
234 }
235
236 LOG(DEBUG) << ss.str();
237 }

◆ send() [1/3]

void iot::mqtt_fast::SocketContext::send ( iot::mqtt_fast::ControlPacket && controlPacket) const
private

Definition at line 208 of file SocketContext.cpp.

208 {
209 send(controlPacket.getPacket());
210 }
std::vector< char > getPacket()
void send(iot::mqtt_fast::ControlPacket &&controlPacket) const

◆ send() [2/3]

void iot::mqtt_fast::SocketContext::send ( iot::mqtt_fast::ControlPacket & controlPacket) const
private

Definition at line 212 of file SocketContext.cpp.

212 {
213 send(controlPacket.getPacket());
214 }

◆ send() [3/3]

void iot::mqtt_fast::SocketContext::send ( std::vector< char > && data) const
private

Definition at line 216 of file SocketContext.cpp.

216 {
217 printData(data);
218 sendToPeer(data.data(), data.size());
219 }
void sendToPeer(const char *chunk, std::size_t chunkLen) const final

◆ sendConnack()

void iot::mqtt_fast::SocketContext::sendConnack ( uint8_t returnCode,
uint8_t flags )

Definition at line 49 of file SocketContext.cpp.

49 {
50 LOG(DEBUG) << "MQTT (fast): Send CONNACK";
51 LOG(DEBUG) << "MQTT (fast): ============";
52
53 send(iot::mqtt_fast::packets::Connack(returnCode, flags));
54 }

◆ sendConnect()

void iot::mqtt_fast::SocketContext::sendConnect ( const std::string & clientId)

Definition at line 42 of file SocketContext.cpp.

42 {
43 LOG(DEBUG) << "MQTT (fast): Send CONNECT";
44 LOG(DEBUG) << "MQTT (fast): ============";
45
47 }

◆ sendDisconnect()

void iot::mqtt_fast::SocketContext::sendDisconnect ( )

Definition at line 133 of file SocketContext.cpp.

133 {
134 LOG(DEBUG) << "MQTT (fast): Send Disconnect";
135 LOG(DEBUG) << "MQTT (fast): ===============";
136
138 }

◆ sendPingreq()

void iot::mqtt_fast::SocketContext::sendPingreq ( )

Definition at line 119 of file SocketContext.cpp.

119 {
120 LOG(DEBUG) << "MQTT (fast): Send Pingreq";
121 LOG(DEBUG) << "MQTT (fast): ============";
122
124 }

◆ sendPingresp()

void iot::mqtt_fast::SocketContext::sendPingresp ( )

Definition at line 126 of file SocketContext.cpp.

126 {
127 LOG(DEBUG) << "MQTT (fast): Send Pingresp";
128 LOG(DEBUG) << "MQTT (fast): =============";
129
131 }

◆ sendPuback()

void iot::mqtt_fast::SocketContext::sendPuback ( uint16_t packetIdentifier)

Definition at line 63 of file SocketContext.cpp.

63 {
64 LOG(DEBUG) << "MQTT (fast): Send PUBACK";
65 LOG(DEBUG) << "MQTT (fast): ===========";
66
67 send(iot::mqtt_fast::packets::Puback(packetIdentifier));
68 }

◆ sendPubcomp()

void iot::mqtt_fast::SocketContext::sendPubcomp ( uint16_t packetIdentifier)

Definition at line 84 of file SocketContext.cpp.

84 {
85 LOG(DEBUG) << "MQTT (fast): Send PUBCOMP";
86 LOG(DEBUG) << "MQTT (fast): ============";
87
88 send(iot::mqtt_fast::packets::Pubcomp(packetIdentifier));
89 }

◆ sendPublish()

void iot::mqtt_fast::SocketContext::sendPublish ( const std::string & topic,
const std::string & message,
bool dup = false,
uint8_t qoS = 0,
bool retain = false )

Definition at line 56 of file SocketContext.cpp.

56 {
57 LOG(DEBUG) << "MQTT (fast): Send PUBLISH";
58 LOG(DEBUG) << "MQTT (fast): ============";
59
60 send(iot::mqtt_fast::packets::Publish(qoS == 0 ? 0 : getPacketIdentifier(), topic, message, dup, qoS, retain));
61 }

◆ sendPubrec()

void iot::mqtt_fast::SocketContext::sendPubrec ( uint16_t packetIdentifier)

Definition at line 70 of file SocketContext.cpp.

70 {
71 LOG(DEBUG) << "MQTT (fast): Send PUBREC";
72 LOG(DEBUG) << "MQTT (fast): ===========";
73
74 send(iot::mqtt_fast::packets::Pubrec(packetIdentifier));
75 }

◆ sendPubrel()

void iot::mqtt_fast::SocketContext::sendPubrel ( uint16_t packetIdentifier)

Definition at line 77 of file SocketContext.cpp.

77 {
78 LOG(DEBUG) << "MQTT (fast): Send PUBREL";
79 LOG(DEBUG) << "MQTT (fast): ===========";
80
81 send(iot::mqtt_fast::packets::Pubrel(packetIdentifier));
82 }

◆ sendSuback()

void iot::mqtt_fast::SocketContext::sendSuback ( uint16_t packetIdentifier,
const std::list< uint8_t > & returnCodes )

Definition at line 98 of file SocketContext.cpp.

98 {
99 LOG(DEBUG) << "MQTT (fast): Send SUBACK";
100 LOG(DEBUG) << "MQTT (fast): ===========";
101
102 send(iot::mqtt_fast::packets::Suback(packetIdentifier, returnCodes));
103 }

◆ sendSubscribe()

void iot::mqtt_fast::SocketContext::sendSubscribe ( std::list< Topic > & topics)

Definition at line 91 of file SocketContext.cpp.

91 {
92 LOG(DEBUG) << "MQTT (fast): Send SUBSCRIBE";
93 LOG(DEBUG) << "MQTT (fast): ==============";
94
96 }

◆ sendUnsuback()

void iot::mqtt_fast::SocketContext::sendUnsuback ( uint16_t packetIdentifier)

Definition at line 112 of file SocketContext.cpp.

112 {
113 LOG(DEBUG) << "MQTT (fast): Send UNSUBACK";
114 LOG(DEBUG) << "MQTT (fast): =============";
115
116 send(iot::mqtt_fast::packets::Unsuback(packetIdentifier));
117 }

◆ sendUnsubscribe()

void iot::mqtt_fast::SocketContext::sendUnsubscribe ( const std::list< std::string > & topics)

Definition at line 105 of file SocketContext.cpp.

105 {
106 LOG(DEBUG) << "MQTT (fast): Send UNSUBSCRIBE";
107 LOG(DEBUG) << "MQTT (fast): ================";
108
110 }

Member Data Documentation

◆ _packetIdentifier

uint16_t iot::mqtt_fast::SocketContext::_packetIdentifier = 0
private

Definition at line 115 of file SocketContext.h.

Referenced by getPacketIdentifier().

◆ controlPacketFactory

iot::mqtt_fast::ControlPacketFactory iot::mqtt_fast::SocketContext::controlPacketFactory
private

Definition at line 113 of file SocketContext.h.


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