Skip to content

Adding direction to virutal bus messages #779

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

Merged
merged 10 commits into from
Mar 3, 2020

Conversation

sou1hacker
Copy link
Contributor

This adds can.Message direction (Rx/Tx) to virtual interface

@codecov
Copy link

codecov bot commented Feb 24, 2020

Codecov Report

Merging #779 into develop will increase coverage by 0.01%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop     #779      +/-   ##
===========================================
+ Coverage    69.52%   69.54%   +0.01%     
===========================================
  Files           70       70              
  Lines         6544     6547       +3     
===========================================
+ Hits          4550     4553       +3     
  Misses        1994     1994              

@sou1hacker sou1hacker marked this pull request as ready for review February 24, 2020 19:39

# Add message to all listening on this channel
all_sent = True
for bus_queue in self.channel:
msg_to_send = msg_copy
if bus_queue is self.queue and self.receive_own_messages:
msg_to_send = deepcopy(msg_copy)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A regular copy would suffice here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@christiansandberg Isn't deepcopy better than copy? I mean doing msg.data = xx after receiving a message in one queue will modify the message for all other virtual interfaces.

Also the original implementation sends the same message instance on every virtual bus. Should we change that to send a different instance since the same argument applies there.

@christiansandberg
Copy link
Collaborator

Yes I know we pass the same msg instance to all interfaces (mostly for performance reasons) and that could be a risk if one of them mutates it for some reason. In general I think a message should be seen as immutable and especially the data part but perhaps it is better to deepcopy all messages instead just to be sure.

@sou1hacker
Copy link
Contributor Author

@christiansandberg changed implementation to create a new deep copied instance of message for each virtual bus queue

@pierreluctg
Copy link
Collaborator

Future improvement can be to implement a copy-on-write (CoW) for messages.

@hardbyte
Copy link
Owner

hardbyte commented Mar 2, 2020

Perhaps worth adding is_rx as an optional attribute to the module level Message class to coordinate with other backends.

@pierreluctg
Copy link
Collaborator

@sou1hacker can you please add unit tests to cover the new features?

  1. Test that is_rx flag is correctly set for virtual buses
  2. Test that each queue receive it's own copy of the message

Thank you

Co-Authored-By: pierreluctg <pierreluctg@gmail.com>
@pierreluctg pierreluctg merged commit 0c698cc into hardbyte:develop Mar 3, 2020
@sou1hacker sou1hacker deleted the message_direction_virtual branch March 3, 2020 20:02
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.

4 participants