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

WIP: Refactor of message dispatching #849

Closed
wants to merge 2 commits into from

Conversation

Pietfried
Copy link
Contributor

@Pietfried Pietfried commented Oct 28, 2024

Describe your changes

Large refactor of message handling:

  • Transfered message dispatching to separate class in order to reuse it in functional blocks
  • 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
  • Added example implementation of one functional block DataTransfer including two tests
  • More functional blocks can follow in subsequent PRs

Issue ticket number and link

Checklist before requesting a review

@hikinggrass hikinggrass mentioned this pull request Oct 30, 2024
4 tasks
Copy link
Contributor

@marcemmers marcemmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think this looks good. Some suggestions or improvements we might want to discuss.

doc/message_dispatching.puml Show resolved Hide resolved

interface v201::DataTransferInterface {
+data_transfer_req(request: DataTransferRequest): std::optional<DataTransferResponse>
+handle_data_transfer_req(call: Call<DataTransferRequest>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace this with a handle_message function that takes an EnhancedMessage<v201::MessageType>?

For this class there is only one message to handle but ideally that should not change the API for these functional blocks. If we later have to add a message to handle we can do it purely in the functional block

doc/message_dispatching.puml Show resolved Hide resolved
lib/ocpp/v201/charge_point.cpp Show resolved Hide resolved
request.vendorId = "test_vendor";
ocpp::Call<DataTransferRequest> call(request, "unique_id_123");

EXPECT_CALL(mock_dispatcher, dispatch_call_result(_)).WillOnce(Invoke([](const json& call_result) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is going to be worth investing some time in making these expectations nicer. Way outside of scope for now but would be smart to do before we make more of these tests.

I don't think we really care whether dispatch_call or dispatch_call_async is called for example, as long as one of those gets called for tests where that is a thing.

Also I would like to create custom matchers to set expectations on specified fields of structs so you don't have to do the invoke construction.

}));

data_transfer.handle_data_transfer_req(call);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests for data_transfer_req in here.

* 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
* Added example implementation of one functional block DataTransfer including two tests

Signed-off-by: Piet Gömpel <[email protected]>
@Pietfried Pietfried force-pushed the feature/message-dispatcher branch from 1e47ab5 to b532341 Compare November 11, 2024 18:36
@Pietfried Pietfried mentioned this pull request Nov 11, 2024
4 tasks
@Pietfried Pietfried closed this Nov 20, 2024
@Pietfried Pietfried deleted the feature/message-dispatcher branch November 20, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants