From d737654698d12f5b76534bccc9a8efc907812e45 Mon Sep 17 00:00:00 2001 From: Kai-Uwe Hermann Date: Thu, 1 Feb 2024 17:52:05 +0100 Subject: [PATCH] Ensure that BootNotification is the first message in the queue Signed-off-by: Kai-Uwe Hermann --- include/ocpp/common/message_queue.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/ocpp/common/message_queue.hpp b/include/ocpp/common/message_queue.hpp index a3ec554f3..41e135f70 100644 --- a/include/ocpp/common/message_queue.hpp +++ b/include/ocpp/common/message_queue.hpp @@ -98,7 +98,7 @@ template class MessageQueue { /// message deque for transaction related messages std::deque>> transaction_message_queue; /// message queue for non-transaction related messages - std::queue>> normal_message_queue; + std::deque>> normal_message_queue; std::shared_ptr> in_flight; std::recursive_mutex message_mutex; std::condition_variable_any cv; @@ -162,7 +162,12 @@ template class MessageQueue { EVLOG_debug << "Adding message to normal message queue"; { std::lock_guard 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(); } @@ -214,7 +219,7 @@ template 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(); } } @@ -401,7 +406,7 @@ template class MessageQueue { EnhancedMessage 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(); @@ -411,7 +416,7 @@ template 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();