-
Notifications
You must be signed in to change notification settings - Fork 422
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
break Node into several separate interfaces #277
Changes from all commits
5133756
e1e9709
a9947d5
4fd3ef2
f205de7
242f459
68ccfa6
b63b960
aafb440
db5e0eb
778dedc
36a206a
8a61d74
40cfa22
345a137
36e746b
c4cb6a2
31e726f
060b69b
10631a9
c59b1d1
821a1ad
18db364
edac3ee
8507ac9
9fd2ad9
9ad8342
6252e72
7150837
1122e25
365705a
dfa0cf7
053cd5b
c18b6ab
28a2cfc
83b610e
f0afcab
23a7728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2016 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCLCPP__CREATE_PUBLISHER_HPP_ | ||
#define RCLCPP__CREATE_PUBLISHER_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "rclcpp/node_interfaces/node_topics_interface.hpp" | ||
#include "rclcpp/publisher_factory.hpp" | ||
#include "rmw/qos_profiles.h" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
template<typename MessageT, typename AllocatorT, typename PublisherT> | ||
std::shared_ptr<PublisherT> | ||
create_publisher( | ||
rclcpp::node_interfaces::NodeTopicsInterface * node_topics, | ||
const std::string & topic_name, | ||
const rmw_qos_profile_t & qos_profile, | ||
bool use_intra_process_comms, | ||
std::shared_ptr<AllocatorT> allocator) | ||
{ | ||
auto publisher_options = rcl_publisher_get_default_options(); | ||
publisher_options.qos = qos_profile; | ||
|
||
auto pub = node_topics->create_publisher( | ||
topic_name, | ||
rclcpp::create_publisher_factory<MessageT, AllocatorT, PublisherT>(allocator), | ||
publisher_options, | ||
use_intra_process_comms); | ||
node_topics->add_publisher(pub); | ||
return std::dynamic_pointer_cast<PublisherT>(pub); | ||
} | ||
|
||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__CREATE_PUBLISHER_HPP_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2016 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCLCPP__CREATE_SUBSCRIPTION_HPP_ | ||
#define RCLCPP__CREATE_SUBSCRIPTION_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
|
||
#include "rclcpp/node_interfaces/node_topics_interface.hpp" | ||
#include "rclcpp/subscription_factory.hpp" | ||
#include "rmw/qos_profiles.h" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
template<typename MessageT, typename CallbackT, typename AllocatorT, typename SubscriptionT> | ||
typename rclcpp::subscription::Subscription<MessageT, AllocatorT>::SharedPtr | ||
create_subscription( | ||
rclcpp::node_interfaces::NodeTopicsInterface * node_topics, | ||
const std::string & topic_name, | ||
CallbackT && callback, | ||
const rmw_qos_profile_t & qos_profile, | ||
rclcpp::callback_group::CallbackGroup::SharedPtr group, | ||
bool ignore_local_publications, | ||
bool use_intra_process_comms, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can the two booleans go into a dedicated struct. Similar to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need an options structure in c++ for these classes, but I didn't want to tackle that in this pr. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm creating an issue for this right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
typename rclcpp::message_memory_strategy::MessageMemoryStrategy<MessageT, AllocatorT>::SharedPtr | ||
msg_mem_strat, | ||
typename std::shared_ptr<AllocatorT> allocator) | ||
{ | ||
auto subscription_options = rcl_subscription_get_default_options(); | ||
subscription_options.qos = qos_profile; | ||
subscription_options.ignore_local_publications = ignore_local_publications; | ||
|
||
auto factory = | ||
rclcpp::create_subscription_factory<MessageT, CallbackT, AllocatorT, SubscriptionT>( | ||
std::forward<CallbackT>(callback), msg_mem_strat, allocator); | ||
|
||
auto sub = node_topics->create_subscription( | ||
topic_name, | ||
factory, | ||
subscription_options, | ||
use_intra_process_comms); | ||
node_topics->add_subscription(sub, group); | ||
return std::dynamic_pointer_cast<SubscriptionT>(sub); | ||
} | ||
|
||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__CREATE_SUBSCRIPTION_HPP_ |
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.
why do we need this factory when we pass the allocator as a template argument?
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.
The factory captures all template code into non template functions so they can be interleaved with non template code in the cpp file. As I mentioned before, I think we could remove the factories now in favor of more linear code that lives in the template functions. The trade off being that there is more code in template functions which increase compile time.
I'd rather do that refactor later though so that we can merge this and let other work build on top in the mean time.