Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add non transform capabilities for intra-process #1849
Add non transform capabilities for intra-process #1849
Changes from all commits
10795a4
066c79b
1ceabc8
6dc5e4e
1334d33
df5f52e
54166ee
6fb0254
7925aee
a5c5504
89c70d1
b76af8e
42cad32
71c3239
da5f12e
f3b7616
3c29a57
1779cd8
c8c4851
6d47368
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this case cannot happen, right?
Now for intraprocess communication, the intraprocess buffer always stores instances of
SubscribedType
, and that will match the type specified in the callback.We don't need a special code path for this case AFAIS.
I also don't think the possible types should have two specializations for ROS messages and type adapters, the possible callbacks are the same in both cases and the argument is always a kind of reference/pointer to SubscribedType.
In the only case we need to aware of the "ROS message type" is in interprocess dispatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the buffer is of SubscribedType, the callback may require a ROSMessage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How?
We're creating a buffer type based on the callback type.
i.e. if your callback is a
smart_ptr<ROSMessage>
or aROSMessage &
the buffer will also be a smart pointer to a ROSMessage.Thus, all those code paths seem unnecessary, and we do have a lot of code paths!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the case (though there is a lot going on here, so I could be wrong).
There can be a difference between the type that the subscription was created with, and the type that the callback is. Consider the following (modified from one of the tests):
When we create the subscription, through many layers we end up creating the buffer as a
std::string
(since that is the SubscribedType here). But our callback is a ROSMessage type, so we need these conversion routines to do the conversion right before we deliver to the callback.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(edit) Read next comment, this one can be ignored.
I don't think that example makes sense, specifying
StringTypeAdapter
is not really useful if the callback is expecting amsg::String
.i.e. what's the benefit of doing that instead of just using
create_subscription<msg::String>
?If there's no benefit, we shouldn't support it.
It adds complexity because you need to keep track of more combinations in the implementation.
I also think we cannot really allow that kind of code if we want the compiler to be able to infer the correct
Subscription
type from the callback type inNode::create_subscription()
.i.e. being able to write
I think there's no way to infer it if both a
Subscription<msg::String>
and aSubscription<StringTypeAdapter>
accept amsg::String
callback. Though I might be wrong, c++ templates and specialization rules are complex and I cannot really remember them.I have also not kept track of what's currently possible, I have a few questions:
create_subscription()
? IIUC, that used to work (*).If the answer to both those question is yes, my only reason to not support that is that I don't see the benefit and it adds complexity.
I guess we can ignore that, but if we later want to not support that to reduce complexity it will be an API breaking change.
(*) If we currently support code as the example above, I guess it will only break if no type is passed and a type adapter is available, though it will still work if there's no type adapter for that message type.
I can also imagine a long and impossible to understand compiler error, which is also something to check and consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my memory is bad, I think we never supported this.
My concern about breaking template parameter inference can be ignored.
The only part I think that it's still valid from my last comment is that supporting that example seems unnecessary, but considering that we already do support it, I think we can move forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked to @audrow and @wjwwood a little bit about this, and part of the idea was so that you could potentially have multiple TypeAdapters for the same types together. Passing the correct TypeAdapter type to the subscription would let the compiler know which of them to choose. That said, I'll let @wjwwood comment here, as he has the best long-term vision for this.
Regardless, I think I'm going to move forward here and address the (minor) points raised by @audrow , and then run CI on the lot again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving forward sounds good.
That's fine.
My comment is about the need to support
Subscription<TypeAdapterT>(..., CallbackUsingRosMessageT callback, ...)
, i.e. allowing to pass a callback that takes some smart pointer or referece to a ROS message type while asking for aTypeAdapterT
subscription.In practice, if the user replace
TypeAdapterT
withRosMessageT
the implementation will do behind the scenes the exact same thing.Allowing that adds a lot of code paths in the dispatching logic, but it doesn't seem to add any value.
Putting it another way, you always want the intraprocess buffer to match the type expected by the callback (as in that way it's possible to avoid the most copies).
I assumed that the type expected by the callback was always the
Subscription<...>
template parameter type, but that doesn't seem to actually be the case.The intraprocess buffer type can currently be different to the callback type, as it's chosen basen on the subscription type, which is suboptimal.
As commented in the previous paragrah, there doesn't seem to be a real reason to allow mixing a
RosMessageT
callback type with aTypeAdapterT
subscription.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened up #1860 to track this (and one other issue) for the future.