Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checking if message queue is running before pushing messages to it #151

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/ocpp/common/message_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ template <typename M> class MessageQueue {

/// \brief pushes a new \p call message onto the message queue
template <class T> void push(Call<T> call) {

if (!running) {
return;
}

auto message = std::make_shared<ControlMessage<M>>(call);
if (this->isTransactionMessage(message)) {
// according to the spec the "transaction related messages" StartTransaction, StopTransaction and
Expand All @@ -346,7 +351,12 @@ template <typename M> class MessageQueue {
/// \returns a future from which the CallResult can be extracted
template <class T> std::future<EnhancedMessage<M>> push_async(Call<T> call) {
auto message = std::make_shared<ControlMessage<M>>(call);
if (this->isTransactionMessage(message)) {

if (!running) {
auto enhanced_message = EnhancedMessage<M>();
enhanced_message.offline = true;
message->promise.set_value(enhanced_message);
} else if (this->isTransactionMessage(message)) {
// according to the spec the "transaction related messages" StartTransaction, StopTransaction and
// MeterValues have to be delivered in chronological order
this->add_to_transaction_message_queue(message);
Expand Down