ros2 / rmw

The ROS Middleware (rmw) Interface.
Apache License 2.0
95 stars 67 forks source link

Push notification on publisher/subscription match #264

Open hidmic opened 4 years ago

hidmic commented 4 years ago

Feature request

Feature description

Currently, the API does not provide (or documents) a generic mechanism to wait for publishers (subscriptions) to match subscriptions (publishers) -- only the current match count is available for query. Thus, code that monitors these counts has to sleep and retry. That's inefficient and potentially brittle. It'd be nice to enable such waits.

Implementation considerations

It seems to me that a new pub/sub event would be the simplest solution. All Tier 1 RMW implementations have a form of pub/sub matching listener that can be leveraged:

It's worth noting that some rcl tests appear to rely on pub/sub matching triggering the graph guard condition. Regardless of that not being true for any of the current Tier 1 RMW implementations, it seems to me that would create too many unwarranted awakes. Also, pub/sub matching does not imply a graph change.

ivanpauno commented 4 years ago

I think that the graph guard condition should be triggered in all graph changes. A summary of graph changes:

About non-dds rmw implementations, FastRTPS didn't use to have wait sets (now FastDDS have). They implemented rmw wait sets with the use of cv and listeners, so I think every non-DDS rmw implementation should be able to do that.

We could also have more fine grained guard conditions in the future.

About the difference between events and the graph guard condition, I think that in the future we could have a single event/condition type that can be added to the wait set instead of the wait set being able to wait in different kinds of objects.

hidmic commented 4 years ago

Alright, as per offline discussion, we've agreed that the global guard condition should be able to detect all the aforementioned ROS graph events. https://github.com/ros2/rmw/pull/272 is a first step in this direction, updating the API spec.

hidmic commented 4 years ago

Alright, since #272 publisher/subscription matching must trigger the graph guard condition. Implementations must now be adapted.