-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor of message dispatching (#864)
* Large refactor of message handling: * Added new class MessageDispatcherInterface that can dispatch OCPP Call, CallResult, CallError * MessageDispatcherInterface became member of ChargePoint classes. The templated methods for sending/dispatching Call, CallResult, CallError have been moved from ChargePoint classes to MessageDispatcher --------- Signed-off-by: Piet Gömpel <[email protected]> Signed-off-by: Kai-Uwe Hermann <[email protected]> Co-authored-by: Kai-Uwe Hermann <[email protected]>
- Loading branch information
1 parent
74f82e3
commit 925e9cd
Showing
16 changed files
with
524 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Message Dispatching Class Diagram | ||
|
||
```mermaid | ||
classDiagram | ||
class MessageDispatcherInterface { | ||
+dispatch_call(const json& call, bool triggered = false) | ||
+dispatch_call_async(const json& call, bool triggered = false): std::future~EnhancedMessage~T~~ | ||
+dispatch_call_result(const json& call_result) | ||
+dispatch_call_error(const json& call_error) | ||
} | ||
class v16_MessageDispatcher { | ||
- MessageQueue& message_queue | ||
- ChargePointConfiguration& configuration | ||
- RegistrationStatus& registration_status | ||
} | ||
class v201_MessageDispatcher { | ||
- MessageQueue& message_queue | ||
- DeviceModel& device_model | ||
- ConnectivityManager& connectivity_manager | ||
- RegistrationStatusEnum& registration_status | ||
} | ||
class v201_DataTransferInterface { | ||
+data_transfer_req(request: DataTransferRequest): std::optional~DataTransferResponse~ | ||
+handle_data_transfer_req(call: Call~DataTransferRequest~) | ||
} | ||
class v201_DataTransfer { | ||
-MessageDispatcherInterface &message_dispatcher | ||
-std::optional~function~ data_transfer_callback | ||
} | ||
class v201_ChargePoint { | ||
std::unique_ptr~MessageDispatcherInterface~ message_dispatcher | ||
std::unique_ptr~v201_DataTransferInterface~ data_transfer | ||
} | ||
class v16_ChargePoint { | ||
std::unique_ptr~MessageDispatcherInterface~ message_dispatcher | ||
} | ||
MessageDispatcherInterface <|-- v16_MessageDispatcher | ||
MessageDispatcherInterface <|-- v201_MessageDispatcher | ||
v201_DataTransferInterface <|-- v201_DataTransfer | ||
MessageDispatcherInterface *-- v201_DataTransfer | ||
MessageDispatcherInterface *-- v201_ChargePoint | ||
v201_DataTransferInterface *-- v201_ChargePoint | ||
MessageDispatcherInterface *-- v16_ChargePoint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
|
||
#pragma once | ||
|
||
#include <ocpp/common/message_queue.hpp> | ||
|
||
namespace ocpp { | ||
|
||
/// \brief Interface for dispatching OCPP messages that shall be send over the websocket. This interface defines | ||
/// dispatching of Call, CallResult and CallError messages. | ||
/// \tparam T Type specifies the OCPP protocol version | ||
template <typename T> class MessageDispatcherInterface { | ||
|
||
public: | ||
virtual ~MessageDispatcherInterface(){}; | ||
|
||
/// \brief Dispatches a Call message. | ||
/// \param call the OCPP Call message. | ||
/// \param triggered indicates if the call was triggered by a TriggerMessage. Default is false. | ||
virtual void dispatch_call(const json& call, bool triggered = false) = 0; | ||
|
||
/// \brief Dispatches a Call message asynchronously. | ||
/// \param call the OCPP Call message. | ||
/// \param triggered indicates if the call was triggered by a TriggerMessage. Default is false. | ||
/// \return std::future<ocpp::EnhancedMessage<T>> Future object containing the enhanced message | ||
/// result of type T. | ||
virtual std::future<ocpp::EnhancedMessage<T>> dispatch_call_async(const json& call, bool triggered = false) = 0; | ||
|
||
/// \brief Dispatches a CallResult message. | ||
/// \param call_result the OCPP CallResult message. | ||
virtual void dispatch_call_result(const json& call_result) = 0; | ||
|
||
/// \brief Dispatches a CallError message. | ||
/// \param call_result the OCPP CallError message. | ||
virtual void dispatch_call_error(const json& call_error) = 0; | ||
}; | ||
|
||
} // namespace ocpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
|
||
#pragma once | ||
|
||
#include <ocpp/common/message_dispatcher.hpp> | ||
#include <ocpp/v16/charge_point_configuration.hpp> | ||
|
||
namespace ocpp { | ||
namespace v16 { | ||
|
||
class MessageDispatcher : public MessageDispatcherInterface<MessageType> { | ||
|
||
public: | ||
MessageDispatcher(ocpp::MessageQueue<MessageType>& message_queue, ChargePointConfiguration& configuration, | ||
std::atomic<RegistrationStatus>& registration_status) : | ||
message_queue(message_queue), configuration(configuration), registration_status(registration_status){}; | ||
void dispatch_call(const json& call, bool triggered = false) override; | ||
std::future<ocpp::EnhancedMessage<MessageType>> dispatch_call_async(const json& call, bool triggered) override; | ||
void dispatch_call_result(const json& call_result) override; | ||
void dispatch_call_error(const json& call_error) override; | ||
|
||
private: | ||
ocpp::MessageQueue<MessageType>& message_queue; | ||
ChargePointConfiguration& configuration; | ||
std::atomic<RegistrationStatus>& registration_status; | ||
}; | ||
|
||
} // namespace v16 | ||
} // namespace ocpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
|
||
#pragma once | ||
|
||
#include <ocpp/common/message_dispatcher.hpp> | ||
#include <ocpp/v201/connectivity_manager.hpp> | ||
#include <ocpp/v201/device_model.hpp> | ||
|
||
namespace ocpp { | ||
namespace v201 { | ||
|
||
class MessageDispatcher : public MessageDispatcherInterface<MessageType> { | ||
|
||
public: | ||
MessageDispatcher(ocpp::MessageQueue<MessageType>& message_queue, DeviceModel& device_model, | ||
std::atomic<RegistrationStatusEnum>& registration_status) : | ||
message_queue(message_queue), device_model(device_model), registration_status(registration_status){}; | ||
void dispatch_call(const json& call, bool triggered = false) override; | ||
std::future<ocpp::EnhancedMessage<MessageType>> dispatch_call_async(const json& call, bool triggered) override; | ||
void dispatch_call_result(const json& call_result) override; | ||
void dispatch_call_error(const json& call_error) override; | ||
|
||
private: | ||
ocpp::MessageQueue<MessageType>& message_queue; | ||
DeviceModel& device_model; | ||
std::atomic<RegistrationStatusEnum>& registration_status; | ||
}; | ||
|
||
} // namespace v201 | ||
} // namespace ocpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.