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

Public Member Functions

 DelayedQueue (Mqtt *mqtt)
 ~DelayedQueue ()
void delayPublish (const utils::Timeval &delay, const iot::mqtt::packets::Publish &publish)
bool empty () const
const ScheduledPublishtop () 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 91 of file Mqtt.h.

Constructor & Destructor Documentation

◆ DelayedQueue()

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

Definition at line 86 of file Mqtt.cpp.

References mqtt.

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

Here is the caller graph for this function:

◆ ~DelayedQueue()

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

Definition at line 90 of file Mqtt.cpp.

90 {
91 delayTimer.cancel();
92 }

References delayTimer.

Member Function Documentation

◆ armDelayTimer()

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

Definition at line 108 of file Mqtt.cpp.

108 {
109 delayTimer.cancel();
110
111 auto delay = top().when - utils::Timeval::currentTime();
112 if (delay < utils::Timeval{}) {
113 delay = utils::Timeval{};
114 }
115
116 delayTimer = core::timer::Timer::singleshotTimer(
117 [this]() {
118 processDue();
119
120 if (!empty()) {
122 }
123 },
124 delay);
125 }
const ScheduledPublish & top() const
Definition Mqtt.cpp:136

References armDelayTimer(), delayTimer, empty(), processDue(), top(), and mqtt::mqttbroker::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::mqttbroker::lib::Mqtt::DelayedQueue::delayPublish ( const utils::Timeval & delay,
const iot::mqtt::packets::Publish & publish )

Definition at line 127 of file Mqtt.cpp.

127 {
128 minHeap.push({utils::Timeval::currentTime() + delay, nextSeq++, publish, delay});
130 }
std::priority_queue< ScheduledPublish, std::vector< ScheduledPublish >, EarlierFirst > minHeap
Definition Mqtt.h:105

References armDelayTimer(), minHeap, and nextSeq.

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

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

◆ empty()

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

Definition at line 132 of file Mqtt.cpp.

132 {
133 return minHeap.empty();
134 }

References minHeap.

Referenced by armDelayTimer(), and processDue().

Here is the caller graph for this function:

◆ pop()

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

Definition at line 140 of file Mqtt.cpp.

140 {
141 minHeap.pop();
142 }

References minHeap.

Referenced by processDue().

Here is the caller graph for this function:

◆ processDue()

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

Definition at line 94 of file Mqtt.cpp.

94 {
95 const auto now = utils::Timeval::currentTime();
96
97 while (!empty() && top().when <= now) {
98 const iot::mqtt::packets::Publish duePublish = top().publish;
99 pop();
100
101 mqtt->broker->publish(
102 mqtt->clientId, duePublish.getTopic(), duePublish.getMessage(), duePublish.getQoS(), duePublish.getRetain());
103
104 mqtt->onPublish(duePublish);
105 }
106 }
iot::mqtt::packets::Publish publish
Definition Mqtt.cpp:66

References empty(), mqtt, mqtt::mqttbroker::lib::Mqtt::onPublish(), pop(), mqtt::mqttbroker::lib::Mqtt::ScheduledPublish::publish, top(), and mqtt::mqttbroker::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::mqttbroker::lib::Mqtt::DelayedQueue::top ( ) const

Definition at line 136 of file Mqtt.cpp.

136 {
137 return minHeap.top();
138 }

References minHeap.

Referenced by armDelayTimer(), and processDue().

Here is the caller graph for this function:

Member Data Documentation

◆ delayTimer

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

Definition at line 107 of file Mqtt.h.

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

◆ minHeap

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

Definition at line 105 of file Mqtt.h.

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

◆ mqtt

Mqtt* mqtt::mqttbroker::lib::Mqtt::DelayedQueue::mqtt
private

Definition at line 103 of file Mqtt.h.

Referenced by DelayedQueue(), and processDue().

◆ nextSeq

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

Definition at line 104 of file Mqtt.h.

Referenced by delayPublish().


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