MQTTSuite
Loading...
Searching...
No Matches
mqtt::mqttintegrator::lib::Mqtt::DelayedQueue Class Reference
Collaboration diagram for mqtt::mqttintegrator::lib::Mqtt::DelayedQueue:

Classes

struct  EarlierFirst

Public Member Functions

 DelayedQueue (Mqtt *mqtt)
 ~DelayedQueue ()
void delayPublish (const utils::Timeval &delay, const iot::mqtt::packets::Publish &publish)
bool empty () const
ScheduledPublish const & top () const
void pop ()

Private Member Functions

void processDue ()
void armDelayTimer ()

Private Attributes

Mqttmqtt
std::size_t nextSeq = 0
std::priority_queue< ScheduledPublish, std::vector< ScheduledPublish >, EarlierFirstminHeap
core::timer::Timer delayTimer

Detailed Description

Definition at line 103 of file Mqtt.h.

Constructor & Destructor Documentation

◆ DelayedQueue()

mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::DelayedQueue ( Mqtt * mqtt)
explicit

Definition at line 196 of file Mqtt.cpp.

References mqtt.

Referenced by mqtt::mqttintegrator::lib::Mqtt::Mqtt().

Here is the caller graph for this function:

◆ ~DelayedQueue()

mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::~DelayedQueue ( )

Definition at line 200 of file Mqtt.cpp.

200 {
201 delayTimer.cancel();
202 }

References delayTimer.

Member Function Documentation

◆ armDelayTimer()

void mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::armDelayTimer ( )
private

Definition at line 217 of file Mqtt.cpp.

217 {
218 delayTimer.cancel();
219
220 auto delay = top().when - utils::Timeval::currentTime();
221 if (delay < utils::Timeval{}) {
222 delay = utils::Timeval{};
223 }
224
225 delayTimer = core::timer::Timer::singleshotTimer(
226 [this]() {
227 processDue();
228
229 if (!empty()) {
231 }
232 },
233 delay);
234 }
ScheduledPublish const & top() const
Definition Mqtt.cpp:245

References armDelayTimer(), delayTimer, empty(), processDue(), top(), and mqtt::mqttintegrator::lib::Mqtt::ScheduledPublish::when.

Referenced by armDelayTimer(), and delayPublish().

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

◆ delayPublish()

void mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::delayPublish ( const utils::Timeval & delay,
const iot::mqtt::packets::Publish & publish )

Definition at line 236 of file Mqtt.cpp.

236 {
237 minHeap.emplace(utils::Timeval::currentTime() + delay, nextSeq++, publish, delay);
239 }
std::priority_queue< ScheduledPublish, std::vector< ScheduledPublish >, EarlierFirst > minHeap
Definition Mqtt.h:122

References armDelayTimer(), minHeap, and nextSeq.

Referenced by mqtt::mqttintegrator::lib::Mqtt::onPublish().

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

◆ empty()

bool mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::empty ( ) const

Definition at line 241 of file Mqtt.cpp.

241 {
242 return minHeap.empty();
243 }

References minHeap.

Referenced by armDelayTimer(), and processDue().

Here is the caller graph for this function:

◆ pop()

void mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::pop ( )

Definition at line 249 of file Mqtt.cpp.

249 {
250 minHeap.pop();
251 }

References minHeap.

Referenced by processDue().

Here is the caller graph for this function:

◆ processDue()

void mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::processDue ( )
private

Definition at line 204 of file Mqtt.cpp.

204 {
205 const auto now = utils::Timeval::currentTime();
206
207 while (!empty() && top().when <= now) {
208 const iot::mqtt::packets::Publish duePublish = top().publish;
209 pop();
210
211 mqtt->sendPublish(duePublish.getTopic(), duePublish.getMessage(), duePublish.getQoS(), duePublish.getRetain());
212
213 mqtt->onPublish(duePublish);
214 }
215 }
iot::mqtt::packets::Publish publish
Definition Mqtt.cpp:68

References empty(), mqtt, mqtt::mqttintegrator::lib::Mqtt::onPublish(), pop(), mqtt::mqttintegrator::lib::Mqtt::ScheduledPublish::publish, top(), and mqtt::mqttintegrator::lib::Mqtt::ScheduledPublish::when.

Referenced by armDelayTimer().

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

◆ top()

Mqtt::ScheduledPublish const & mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::top ( ) const

Definition at line 245 of file Mqtt.cpp.

245 {
246 return minHeap.top();
247 }

References minHeap.

Referenced by armDelayTimer(), and processDue().

Here is the caller graph for this function:

Member Data Documentation

◆ delayTimer

core::timer::Timer mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::delayTimer
private

Definition at line 124 of file Mqtt.h.

Referenced by armDelayTimer(), and ~DelayedQueue().

◆ minHeap

std::priority_queue<ScheduledPublish, std::vector<ScheduledPublish>, EarlierFirst> mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::minHeap
private

Definition at line 122 of file Mqtt.h.

Referenced by delayPublish(), empty(), pop(), and top().

◆ mqtt

Mqtt* mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::mqtt
private

Definition at line 120 of file Mqtt.h.

Referenced by DelayedQueue(), and processDue().

◆ nextSeq

std::size_t mqtt::mqttintegrator::lib::Mqtt::DelayedQueue::nextSeq = 0
private

Definition at line 121 of file Mqtt.h.

Referenced by delayPublish().


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