Implementation for rmw_get_pub/sub_info_by_topic#97
Conversation
Implementation for the rmw_get_publishers_info_by_topic and rmw_get_subscriptions_info_by_topic methods. Signed-off-by: Dennis Potman <[email protected]>
|
This PR resolves issue #82 (may need refactoring in case the |
eboasson
left a comment
There was a problem hiding this comment.
Thanks @dennis-adlink for this pull request. As I want to see the Cyclone RMW layer complete, I decided to respond to @ivanpauno's request in #87. It's really mostly nit-picking, the only mistake is in the error handling in get_endpoint_info_by_topic, but I also think there might be a problem in the underlying rmw interfaces ...
| dds_qos_t * qos = dds_create_qos(); | ||
| if (dds_get_qos(handle, qos) < 0) { | ||
| RMW_SET_ERROR_MSG("get_readwrite_qos: invalid handle"); | ||
| goto error; |
There was a problem hiding this comment.
I would suggest removing the goto errors here, considering that only the case of dds_get_qos returning an error needs some error handling.
| void * msg = NULL; | ||
| int32_t n; | ||
| while ((n = dds_take(rd, &msg, &info, 1, 1)) == 1) { | ||
| bool cont = true; |
There was a problem hiding this comment.
All filter/map functions passed to rmw_collect_data_for_endpoint always return true, and so the cont variable isn't needed. I would suggest removing the return value.
| typedef std::map<dds_builtintopic_guid_t, std::pair<std::string, std::string>> node_cache_t; | ||
|
|
||
| static rmw_ret_t get_node_name( | ||
| dds_entity_t rd, |
There was a problem hiding this comment.
Perhaps it would be better to indicate more clearly that rd must be a reader of the "participant" built-in topic — and possible also to assert that is. A name change would do the trick, ppant_rd could be an option (but I find it hard to guess how much confusion it would eliminate or create for readers that don't know Cyclone well).
| static rmw_ret_t | ||
| set_rmw_topic_endpoint_info( | ||
| node_cache_t & node_cache, | ||
| dds_entity_t rd, |
There was a problem hiding this comment.
See comment concerning rd in get_node_name — the same applies here.
| node_name = "_NODE_NAME_UNKNOWN_"; | ||
| node_ns = "_NODE_NAMESPACE_UNKNOWN_"; | ||
| } | ||
| return RMW_RET_OK; |
There was a problem hiding this comment.
Not returning a value would eliminate the return value checks later on.
| { | ||
| return ret; | ||
| } | ||
| topic_endpoint_info.qos_profile = epinfo.qos_profile; |
There was a problem hiding this comment.
Shouldn't this be rmw_topic_endpoint_info_set_qos_profile to continue the pattern?
| "/"); | ||
| info.topic_type = std::string(demangled_type) + std::string(cm_typ[2]); | ||
| } else { | ||
| return true; |
There was a problem hiding this comment.
Perhaps add a comment that this skips a non-ROS2 endpoint?
| node_impl->enth, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL)) < 0) | ||
| { | ||
| RMW_SET_ERROR_MSG("get_endpoint_info_by_topic: failed to create reader"); | ||
| return RMW_RET_ERROR; |
There was a problem hiding this comment.
I think this is missing a call to rmw_topic_endpoint_info_array_fini because the init_with_size function before allocated memory. However, I'm not entirely certain of this because array_fini invokes endpoint_info_fini on its elements and I don't see a guarantee the array init_with_size allocates is properly initialized.
There was a problem hiding this comment.
If you first call get_zero_initialized_topic_endpoint_info_array, and then init_with_size, it shouldn't be a problem to call rmw_topic_endpoint_info_array_fini when something fails.
| handle_topic_endpoint_info_fini(&endpoint_info->info_array[n], allocator); | ||
| } | ||
| dds_delete(rd); | ||
| return ret; |
| rmw_topic_endpoint_info_array_t * endpoint_info) | ||
| { | ||
| auto node_impl = static_cast<CddsNode *>(node->data); | ||
| const auto re_typ = std::regex("^(.*::)dds_::(.*)_$", std::regex::extended); |
There was a problem hiding this comment.
I think it would make sense to create a function to demangle topic names/types, with a parameter specifying whether it concerns data, requests or responses. There was some duplication already, but this adds yet another one and having regexes all over the place is a bit unpleasant.
…fixed enpoint_info_array_fini and a few other minor fixes Signed-off-by: Dennis Potman <[email protected]>
|
@eboasson Thanks for the review! I fixed the issues in my latest commit:
|
Signed-off-by: Dennis Potman <[email protected]>
|
One more commit to refactor out the extra call to |
Signed-off-by: Erik Boasson <[email protected]>
|
Thanks @dennis-adlink. The only thing was a warning for an unused argument in a release build, I've pushed a fix for that. @ivanpauno I think it can be merged, but perhaps you would like to have a quick look or do a CI run first? |
Yes, I will run CI together with the |
ivanpauno
left a comment
There was a problem hiding this comment.
I think error handling should be fixed before merging, otherwise LGTM!
| node_impl->enth, DDS_BUILTIN_TOPIC_DCPSPARTICIPANT, NULL, NULL)) < 0) | ||
| { | ||
| RMW_SET_ERROR_MSG("get_endpoint_info_by_topic: failed to create reader"); | ||
| return RMW_RET_ERROR; |
There was a problem hiding this comment.
If you first call get_zero_initialized_topic_endpoint_info_array, and then init_with_size, it shouldn't be a problem to call rmw_topic_endpoint_info_array_fini when something fails.
|
I'm going to send a PR to fix that, because it's confusing (and incongruent with other arrays defined in
Sounds good! |
Signed-off-by: Dennis Potman <[email protected]>
Implementation for the
rmw_get_publishers_info_by_topicandrmw_get_subscriptions_info_by_topicmethods, and some related refactoring:rmw_collect_tptyp_for_kindto the more genericrmw_collect_data_for_endpointdds_qos_to_rmw_qosfromget_readwrite_qosWhen this PR is merged, the rcl test
test_rcl_get_publishers_subscription_info_by_topiccan be enabled for Cyclone; I'll create a PR for this.