Skip to content

Commit

Permalink
Ensure that BootNotification is the first message in the queue
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Feb 1, 2024
1 parent d3971bd commit d737654
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ template <typename M> class MessageQueue {
/// message deque for transaction related messages
std::deque<std::shared_ptr<ControlMessage<M>>> transaction_message_queue;
/// message queue for non-transaction related messages
std::queue<std::shared_ptr<ControlMessage<M>>> normal_message_queue;
std::deque<std::shared_ptr<ControlMessage<M>>> normal_message_queue;
std::shared_ptr<ControlMessage<M>> in_flight;
std::recursive_mutex message_mutex;
std::condition_variable_any cv;
Expand Down Expand Up @@ -162,7 +162,12 @@ template <typename M> class MessageQueue {
EVLOG_debug << "Adding message to normal message queue";
{
std::lock_guard<std::recursive_mutex> lk(this->message_mutex);
this->normal_message_queue.push(message);
// A BootNotification message should always jump the queue
if (message->messageType == M::BootNotification) {
this->normal_message_queue.push_front(message);
} else {
this->normal_message_queue.push_back(message);
}
this->new_message = true;
this->check_queue_sizes();
}
Expand Down Expand Up @@ -214,7 +219,7 @@ template <typename M> class MessageQueue {
EVLOG_warning << "Dropping " << number_of_dropped_messages << " messages from normal message queue.";

for (int i = 0; i < number_of_dropped_messages; i++) {
this->normal_message_queue.pop();
this->normal_message_queue.pop_front();
}
}

Expand Down Expand Up @@ -401,7 +406,7 @@ template <typename M> class MessageQueue {
EnhancedMessage<M> enhanced_message;
enhanced_message.offline = true;
this->in_flight->promise.set_value(enhanced_message);
this->normal_message_queue.pop();
this->normal_message_queue.pop_front();
}
}
this->reset_in_flight();
Expand All @@ -411,7 +416,7 @@ template <typename M> class MessageQueue {
this->current_message_timeout(message->message_attempts));
switch (queue_type) {
case QueueType::Normal:
this->normal_message_queue.pop();
this->normal_message_queue.pop_front();
break;
case QueueType::Transaction:
this->transaction_message_queue.pop_front();
Expand Down

0 comments on commit d737654

Please sign in to comment.