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:
parent
7494350ad2
commit
7f714a8601
3 changed files with 19 additions and 16 deletions
|
@ -123,8 +123,10 @@ public:
|
|||
* \param[in] qos_history_depth The depth of the publisher message queue.
|
||||
* \return Shared pointer to the created publisher.
|
||||
*/
|
||||
template<typename MessageT, typename Alloc = std::allocator<void>>
|
||||
typename rclcpp::publisher::Publisher<MessageT, Alloc>::SharedPtr
|
||||
template<
|
||||
typename MessageT, typename Alloc = std::allocator<void>,
|
||||
typename PublisherT = ::rclcpp::publisher::Publisher<MessageT, Alloc>>
|
||||
std::shared_ptr<PublisherT>
|
||||
create_publisher(
|
||||
const std::string & topic_name, size_t qos_history_depth,
|
||||
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.
|
||||
* \return Shared pointer to the created publisher.
|
||||
*/
|
||||
template<typename MessageT, typename Alloc = std::allocator<void>>
|
||||
typename rclcpp::publisher::Publisher<MessageT, Alloc>::SharedPtr
|
||||
template<
|
||||
typename MessageT, typename Alloc = std::allocator<void>,
|
||||
typename PublisherT = ::rclcpp::publisher::Publisher<MessageT, Alloc>>
|
||||
std::shared_ptr<PublisherT>
|
||||
create_publisher(
|
||||
const std::string & topic_name,
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_default,
|
||||
|
|
|
@ -50,8 +50,8 @@ namespace rclcpp
|
|||
namespace node
|
||||
{
|
||||
|
||||
template<typename MessageT, typename Alloc>
|
||||
typename rclcpp::publisher::Publisher<MessageT, Alloc>::SharedPtr
|
||||
template<typename MessageT, typename Alloc, typename PublisherT>
|
||||
std::shared_ptr<PublisherT>
|
||||
Node::create_publisher(
|
||||
const std::string & topic_name, size_t qos_history_depth,
|
||||
std::shared_ptr<Alloc> allocator)
|
||||
|
@ -61,11 +61,11 @@ Node::create_publisher(
|
|||
}
|
||||
rmw_qos_profile_t qos = rmw_qos_profile_default;
|
||||
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>
|
||||
typename publisher::Publisher<MessageT, Alloc>::SharedPtr
|
||||
template<typename MessageT, typename Alloc, typename PublisherT>
|
||||
std::shared_ptr<PublisherT>
|
||||
Node::create_publisher(
|
||||
const std::string & topic_name, const rmw_qos_profile_t & qos_profile,
|
||||
std::shared_ptr<Alloc> allocator)
|
||||
|
@ -78,12 +78,12 @@ Node::create_publisher(
|
|||
publisher_options.qos = qos_profile;
|
||||
|
||||
auto message_alloc =
|
||||
std::make_shared<typename publisher::Publisher<MessageT, Alloc>::MessageAlloc>(
|
||||
std::make_shared<typename PublisherT::MessageAlloc>(
|
||||
*allocator.get());
|
||||
publisher_options.allocator = allocator::get_rcl_allocator<MessageT>(
|
||||
*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);
|
||||
|
||||
if (use_intra_process_comms_) {
|
||||
|
|
|
@ -204,13 +204,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Send a message to the topic for this publisher.
|
||||
/**
|
||||
* This function is templated on the input message type, MessageT.
|
||||
* \param[in] msg A shared pointer to the message to send.
|
||||
*/
|
||||
void
|
||||
virtual void
|
||||
publish(std::unique_ptr<MessageT, MessageDeleter> & msg)
|
||||
{
|
||||
this->do_inter_process_publish(msg.get());
|
||||
|
@ -242,7 +241,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
virtual void
|
||||
publish(const std::shared_ptr<MessageT> & msg)
|
||||
{
|
||||
// Avoid allocating when not using intra process.
|
||||
|
@ -261,7 +260,7 @@ public:
|
|||
return this->publish(unique_msg);
|
||||
}
|
||||
|
||||
void
|
||||
virtual void
|
||||
publish(std::shared_ptr<const MessageT> msg)
|
||||
{
|
||||
// Avoid allocating when not using intra process.
|
||||
|
@ -280,7 +279,7 @@ public:
|
|||
return this->publish(unique_msg);
|
||||
}
|
||||
|
||||
void
|
||||
virtual void
|
||||
publish(const MessageT & msg)
|
||||
{
|
||||
// Avoid allocating when not using intra process.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue