open Node/Publisher API for allowing inheritance (#258)

* (dev) template create_publisher with publisher type

* (dev) template publisher type for dynamic publisher type instantiation

* (dev) make Publisher::publish function virtual

* (fix) uncrustify

* different indentation of long template declaration
This commit is contained in:
Karsten Knese 2016-11-01 15:07:58 -07:00 committed by GitHub
parent 7494350ad2
commit 7f714a8601
3 changed files with 19 additions and 16 deletions

View file

@ -123,8 +123,10 @@ public:
* \param[in] qos_history_depth The depth of the publisher message queue. * \param[in] qos_history_depth The depth of the publisher message queue.
* \return Shared pointer to the created publisher. * \return Shared pointer to the created publisher.
*/ */
template<typename MessageT, typename Alloc = std::allocator<void>> template<
typename rclcpp::publisher::Publisher<MessageT, Alloc>::SharedPtr typename MessageT, typename Alloc = std::allocator<void>,
typename PublisherT = ::rclcpp::publisher::Publisher<MessageT, Alloc>>
std::shared_ptr<PublisherT>
create_publisher( create_publisher(
const std::string & topic_name, size_t qos_history_depth, const std::string & topic_name, size_t qos_history_depth,
std::shared_ptr<Alloc> allocator = nullptr); std::shared_ptr<Alloc> allocator = nullptr);
@ -135,8 +137,10 @@ public:
* \param[in] qos_profile The quality of service profile to pass on to the rmw implementation. * \param[in] qos_profile The quality of service profile to pass on to the rmw implementation.
* \return Shared pointer to the created publisher. * \return Shared pointer to the created publisher.
*/ */
template<typename MessageT, typename Alloc = std::allocator<void>> template<
typename rclcpp::publisher::Publisher<MessageT, Alloc>::SharedPtr typename MessageT, typename Alloc = std::allocator<void>,
typename PublisherT = ::rclcpp::publisher::Publisher<MessageT, Alloc>>
std::shared_ptr<PublisherT>
create_publisher( create_publisher(
const std::string & topic_name, const std::string & topic_name,
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default, const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default,

View file

@ -50,8 +50,8 @@ namespace rclcpp
namespace node namespace node
{ {
template<typename MessageT, typename Alloc> template<typename MessageT, typename Alloc, typename PublisherT>
typename rclcpp::publisher::Publisher<MessageT, Alloc>::SharedPtr std::shared_ptr<PublisherT>
Node::create_publisher( Node::create_publisher(
const std::string & topic_name, size_t qos_history_depth, const std::string & topic_name, size_t qos_history_depth,
std::shared_ptr<Alloc> allocator) std::shared_ptr<Alloc> allocator)
@ -61,11 +61,11 @@ Node::create_publisher(
} }
rmw_qos_profile_t qos = rmw_qos_profile_default; rmw_qos_profile_t qos = rmw_qos_profile_default;
qos.depth = qos_history_depth; qos.depth = qos_history_depth;
return this->create_publisher<MessageT, Alloc>(topic_name, qos, allocator); return this->create_publisher<MessageT, Alloc, PublisherT>(topic_name, qos, allocator);
} }
template<typename MessageT, typename Alloc> template<typename MessageT, typename Alloc, typename PublisherT>
typename publisher::Publisher<MessageT, Alloc>::SharedPtr std::shared_ptr<PublisherT>
Node::create_publisher( Node::create_publisher(
const std::string & topic_name, const rmw_qos_profile_t & qos_profile, const std::string & topic_name, const rmw_qos_profile_t & qos_profile,
std::shared_ptr<Alloc> allocator) std::shared_ptr<Alloc> allocator)
@ -78,12 +78,12 @@ Node::create_publisher(
publisher_options.qos = qos_profile; publisher_options.qos = qos_profile;
auto message_alloc = auto message_alloc =
std::make_shared<typename publisher::Publisher<MessageT, Alloc>::MessageAlloc>( std::make_shared<typename PublisherT::MessageAlloc>(
*allocator.get()); *allocator.get());
publisher_options.allocator = allocator::get_rcl_allocator<MessageT>( publisher_options.allocator = allocator::get_rcl_allocator<MessageT>(
*message_alloc.get()); *message_alloc.get());
auto publisher = publisher::Publisher<MessageT, Alloc>::make_shared( auto publisher = std::make_shared<PublisherT>(
node_handle_, topic_name, publisher_options, message_alloc); node_handle_, topic_name, publisher_options, message_alloc);
if (use_intra_process_comms_) { if (use_intra_process_comms_) {

View file

@ -204,13 +204,12 @@ public:
} }
} }
/// Send a message to the topic for this publisher. /// Send a message to the topic for this publisher.
/** /**
* This function is templated on the input message type, MessageT. * This function is templated on the input message type, MessageT.
* \param[in] msg A shared pointer to the message to send. * \param[in] msg A shared pointer to the message to send.
*/ */
void virtual void
publish(std::unique_ptr<MessageT, MessageDeleter> & msg) publish(std::unique_ptr<MessageT, MessageDeleter> & msg)
{ {
this->do_inter_process_publish(msg.get()); this->do_inter_process_publish(msg.get());
@ -242,7 +241,7 @@ public:
} }
} }
void virtual void
publish(const std::shared_ptr<MessageT> & msg) publish(const std::shared_ptr<MessageT> & msg)
{ {
// Avoid allocating when not using intra process. // Avoid allocating when not using intra process.
@ -261,7 +260,7 @@ public:
return this->publish(unique_msg); return this->publish(unique_msg);
} }
void virtual void
publish(std::shared_ptr<const MessageT> msg) publish(std::shared_ptr<const MessageT> msg)
{ {
// Avoid allocating when not using intra process. // Avoid allocating when not using intra process.
@ -280,7 +279,7 @@ public:
return this->publish(unique_msg); return this->publish(unique_msg);
} }
void virtual void
publish(const MessageT & msg) publish(const MessageT & msg)
{ {
// Avoid allocating when not using intra process. // Avoid allocating when not using intra process.