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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
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

+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)
+new_message_id(): MessageId
Copy link
Contributor

@marcemmers marcemmers Oct 29, 2024

Choose a reason for hiding this comment

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

Do we even need to bother with message IDs for users of this layer? The layer should be able to take care of it itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this functionality does not necessarily have to be part of this interface

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at it, I think we might want to move the createMessageId functionality out of the message queue, it can be a free function. Then on construction of a Call<T> type we can generate a message id internally and essentially hide this value.

@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.

+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)
+new_message_id(): MessageId
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at it, I think we might want to move the createMessageId functionality out of the message queue, it can be a free function. Then on construction of a Call<T> type we can generate a message id internally and essentially hide this value.


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


@startuml

interface MessageDispatcherInterface {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could also be named IHandleMessage if we really want haha

@@ -75,6 +75,11 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
}

initialize(evse_connector_structure, message_log_path);

this->message_dispatcher =
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to check here if message_queue exists because this constructor is sometimes called with nullptr.

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]>
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