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

Fix std::function disambiguation in Windows #27

Merged
merged 9 commits into from
Apr 30, 2015
Merged

Conversation

esteve
Copy link
Member

@esteve esteve commented Apr 29, 2015

@esteve esteve added the in progress Actively being worked on (Kanban column) label Apr 29, 2015
FunctorT,
2,
typename rclcpp::service::Service<ServiceT>::SharedPtr
>::type
Copy link
Member

Choose a reason for hiding this comment

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

The indentation looks difficult to "parse". Would one of the following be clearer?

  typename function_arity
  <
    FunctorT,
    2,
    typename rclcpp::service::Service<ServiceT>::SharedPtr
  >::type

or

template<typename ServiceT, typename FunctorT>
typename function_arity<
  FunctorT,
  2,
  typename rclcpp::service::Service<ServiceT>::SharedPtr>::type

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended reformatting this code with the second style.

@wjwwood
Copy link
Member

wjwwood commented Apr 29, 2015

Can you explain this a little bit? I'm confused as to why the return type of create_service had to be rolled into this. I can see why the additional FunctorT template variable is needed, but it isn't clear to me how the return type is involved.

If we want to merge this I think we should take some time to make it cleaner, focusing if possible on the signature of the method, which is what the users will be exposed to. Maybe we could do a dispatch function which takes either callback and then calls an implementation function which has all of this template magic added. That way the user facing API isn't as busy looking. @esteve do you think it is possible to hide some of this in the implementation?

@esteve
Copy link
Member Author

esteve commented Apr 29, 2015

@wjwwood this basically checks that the callback passed as the functor argument either has two or three arguments (without and with the request header). I tried getting this working with std::enable_if and std::is_convertible, but unfortunately VS still thinks that the two callback types are interchangeable. My guess is that it's related to "Q. When will you implement Expression SFINAE?" in http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx

The return type is needed in the function_arity template because it's used in std::enable_if so that the templated function can return an appropriate return type.

I agree with making this more readable and expressive, the generated Doxygen docs will look horrible as it is now. I think we could change this a little bit so that there's only one create_service method, that gets passed a std::function with variadic arguments and check the number of arguments and their type inside the create_service method.

@esteve
Copy link
Member Author

esteve commented Apr 30, 2015

I refactored the code a little bit and now create_service is not as ugly as it was, it dispatches internally to an appropriate version of create_service_internal depending on the number of arguments of the callback passed to it. We could check the type of the arguments of the callback, but maybe this is enough.

@esteve
Copy link
Member Author

esteve commented Apr 30, 2015

I ended up adding support for checking the types of the arguments of the callback passed as well, this should make create_service more robust.

@esteve
Copy link
Member Author

esteve commented Apr 30, 2015

@dirk-thomas @tfoote @wjwwood when you have a moment, please have a look at the latest changes. The Windows slave builds fine now: http://54.183.26.131:8080/view/ros2/job/ros2_batch_ci_windows/212/

Thanks.


/* Create and return a Service. */
template<typename ServiceT>
template<typename ServiceT, typename F>
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename F to something "longer" like CallbackT?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that a more verbose name would be good.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@dirk-thomas
Copy link
Member

Looks much cleaner to me: +1

@esteve
Copy link
Member Author

esteve commented Apr 30, 2015

I had to remove the check for the third argument for callbacks that take a request header because it failed with simpler callbacks. Apparently checking for arity is not enough and std::enable_if evaluates every clause.

@esteve
Copy link
Member Author

esteve commented Apr 30, 2015

This is the code I had to disable:

02a41cd

@wjwwood
Copy link
Member

wjwwood commented Apr 30, 2015

+1 The API looks much cleaner now.

esteve added a commit that referenced this pull request Apr 30, 2015
Fix std::function disambiguation in Windows
@esteve esteve merged commit a5138a2 into master Apr 30, 2015
@esteve esteve removed the in progress Actively being worked on (Kanban column) label Apr 30, 2015
@esteve esteve deleted the callable-compatible branch April 30, 2015 22:15
@tfoote
Copy link
Contributor

tfoote commented Apr 30, 2015

lgtm

@dirk-thomas
Copy link
Member

+1

Please squash before merging.

DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
* ros2GH-61 Read topic directly from message when playing and allow to play multiple topics

* ros2GH-61 Add test for SqliteStorage and update old ones

* ros2GH-62 Extend function to poll for any number of specified topics

* ros2GH-62 Allow subscription to several topics

* ros2GH-61 Obtain the topic name directly from the database

- Uses a JOIN instead of mapping the topic_id to the name in code

* ros2GH-61 Cache read row in result iterator

This allows repeated dereferencing on same row without quering the
database again.

* ros2GH-62 Change demo-record to allow specifying multiple topics

* ros2GH-62 Add test to write non-string topic + refactoring

* ros2GH-62 Add test for subscription to multiple topics

* ros2GH-62 Cleanup

* ros2GH-62 Simplify test setup

* ros2GH-61 Cleanup

* ros2GH-61 consolidate storage integration test

* ros2GH-62 Consolidate write integration tests

* ros2GH-61 enhance read integration test to check multiple topics

* ros2GH-62 Improve rosbag integration test

* ros2GH-62: Polish rosbag2_rosbag_node_test

* ros2GH-62 Fix cpplint

* ros2GH-62 Fix memory leak in rosbag helper

* ros2GH-62 Cleanup of subscriptions

* ros2GH-62 do not use flaky timers in rosbag2_write_integration_test

* ros2GH-62 Use rmw_serialize_message_t consistently in test helper classes

* ros2GH-73 Use test_msgs in read_integration_test

* ros2GH-26 Cleanup: fix alphabetic orderung
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
* ros2GH-27 Implement discovery for new topics after startup

- this allows new topics to be discovered also after startup.
- as a consquence, ros2 bag record won't throw any exception anymore if the specified topics are not available at startup
- each time the recorder subscribes to a new topic, this will be logged to console

* ros2GH-27 Provide polling frequency as option

- make option available in RecordOptions
- set to 100ms for now

* ros2GH-27 Stop topic polling if subscription setup is complete

* ros2GH-27 Minor refactoring for readability

* ros2GH-27 Fix build after rebase

* ros2GH-145 add no-discovery option to ros2 bag record

* ros2GH-27 Refactor subscribing mechanism

- use set for subscribed topics instead of vector
- perform the asynchronous call only when discovery is needed

* ros2GH-27 Expose polling-interval as cli option

* ros2GH-27 Minor refactoring

* ros2GH-27 Refactor recorder

- naming of methods
- emphasize similarity between first subscription and discovery loop

* small touch ups

* remove launch from function name
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.

None yet

4 participants