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 194 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 198 of file Mqtt.cpp.

198 {
199 delayTimer.cancel();
200 }

References delayTimer.

Member Function Documentation

◆ armDelayTimer()

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

Definition at line 213 of file Mqtt.cpp.

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

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 232 of file Mqtt.cpp.

232 {
233 minHeap.emplace(utils::Timeval::currentTime() + delay, nextSeq++, publish, delay);
235 }
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 237 of file Mqtt.cpp.

237 {
238 return minHeap.empty();
239 }

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 245 of file Mqtt.cpp.

245 {
246 minHeap.pop();
247 }

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 202 of file Mqtt.cpp.

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

References empty(), mqtt, 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 241 of file Mqtt.cpp.

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

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: