rclcpp  master
C++ ROS Client Library API
Classes | Public Member Functions | List of all members
rclcpp::experimental::IntraProcessManager Class Reference

This class performs intra process communication between nodes. More...

#include <intra_process_manager.hpp>

Public Member Functions

 IntraProcessManager ()
 
virtual ~IntraProcessManager ()
 
uint64_t add_subscription (rclcpp::experimental::SubscriptionIntraProcessBase::SharedPtr subscription)
 Register a subscription with the manager, returns subscriptions unique id. More...
 
void remove_subscription (uint64_t intra_process_subscription_id)
 Unregister a subscription using the subscription's unique id. More...
 
uint64_t add_publisher (rclcpp::PublisherBase::SharedPtr publisher)
 Register a publisher with the manager, returns the publisher unique id. More...
 
void remove_publisher (uint64_t intra_process_publisher_id)
 Unregister a publisher using the publisher's unique id. More...
 
template<typename MessageT , typename Alloc = std::allocator<void>, typename Deleter = std::default_delete<MessageT>>
void do_intra_process_publish (uint64_t intra_process_publisher_id, std::unique_ptr< MessageT, Deleter > message, std::shared_ptr< typename allocator::AllocRebind< MessageT, Alloc >::allocator_type > allocator)
 Publishes an intra-process message, passed as a unique pointer. More...
 
template<typename MessageT , typename Alloc = std::allocator<void>, typename Deleter = std::default_delete<MessageT>>
std::shared_ptr< const MessageT > do_intra_process_publish_and_return_shared (uint64_t intra_process_publisher_id, std::unique_ptr< MessageT, Deleter > message, std::shared_ptr< typename allocator::AllocRebind< MessageT, Alloc >::allocator_type > allocator)
 
bool matches_any_publishers (const rmw_gid_t *id) const
 Return true if the given rmw_gid_t matches any stored Publishers. More...
 
size_t get_subscription_count (uint64_t intra_process_publisher_id) const
 Return the number of intraprocess subscriptions that are matched with a given publisher id. More...
 
rclcpp::experimental::SubscriptionIntraProcessBase::SharedPtr get_subscription_intra_process (uint64_t intra_process_subscription_id)
 

Detailed Description

This class performs intra process communication between nodes.

This class is used in the creation of publishers and subscriptions. A singleton instance of this class is owned by a rclcpp::Context and a rclcpp::Node can use an associated Context to get an instance of this class. Nodes which do not have a common Context will not exchange intra process messages because they do not share access to the same instance of this class.

When a Node creates a subscription, it can also create a helper class, called SubscriptionIntraProcess, meant to receive intra process messages. It can be registered with this class. It is also allocated an id which is unique among all publishers and subscriptions in this process and that is associated to the subscription.

When a Node creates a publisher, as with subscriptions, a helper class can be registered with this class. This is required in order to publish intra-process messages. It is also allocated an id which is unique among all publishers and subscriptions in this process and that is associated to the publisher.

When a publisher or a subscription are registered, this class checks to see which other subscriptions or publishers it will communicate with, i.e. they have the same topic and compatible QoS.

When the user publishes a message, if intra-process communication is enabled on the publisher, the message is given to this class. Using the publisher id, a list of recipients for the message is selected. For each subscription in the list, this class stores the message, whether sharing ownership or making a copy, in a buffer associated with the subscription helper class.

The subscription helper class contains a buffer where published intra-process messages are stored until they are taken from the subscription. Depending on the data type stored in the buffer, the subscription helper class can request either shared or exclusive ownership on the message.

Thus, when an intra-process message is published, this class knows how many intra-process subscriptions needs it and how many require ownership. This information allows this class to operate efficiently by performing the fewest number of copies of the message required.

This class is neither CopyConstructable nor CopyAssignable.

Constructor & Destructor Documentation

◆ IntraProcessManager()

rclcpp::experimental::IntraProcessManager::IntraProcessManager ( )

◆ ~IntraProcessManager()

virtual rclcpp::experimental::IntraProcessManager::~IntraProcessManager ( )
virtual

Member Function Documentation

◆ add_subscription()

uint64_t rclcpp::experimental::IntraProcessManager::add_subscription ( rclcpp::experimental::SubscriptionIntraProcessBase::SharedPtr  subscription)

Register a subscription with the manager, returns subscriptions unique id.

This method stores the subscription intra process object, together with the information of its wrapped subscription (i.e. topic name and QoS).

In addition this generates a unique intra process id for the subscription.

Parameters
subscriptionthe SubscriptionIntraProcess to register.
Returns
an unsigned 64-bit integer which is the subscription's unique id.

◆ remove_subscription()

void rclcpp::experimental::IntraProcessManager::remove_subscription ( uint64_t  intra_process_subscription_id)

Unregister a subscription using the subscription's unique id.

This method does not allocate memory.

Parameters
intra_process_subscription_idid of the subscription to remove.

◆ add_publisher()

uint64_t rclcpp::experimental::IntraProcessManager::add_publisher ( rclcpp::PublisherBase::SharedPtr  publisher)

Register a publisher with the manager, returns the publisher unique id.

This method stores the publisher intra process object, together with the information of its wrapped publisher (i.e. topic name and QoS).

In addition this generates a unique intra process id for the publisher.

Parameters
publisherpublisher to be registered with the manager.
Returns
an unsigned 64-bit integer which is the publisher's unique id.

◆ remove_publisher()

void rclcpp::experimental::IntraProcessManager::remove_publisher ( uint64_t  intra_process_publisher_id)

Unregister a publisher using the publisher's unique id.

This method does not allocate memory.

Parameters
intra_process_publisher_idid of the publisher to remove.

◆ do_intra_process_publish()

template<typename MessageT , typename Alloc = std::allocator<void>, typename Deleter = std::default_delete<MessageT>>
void rclcpp::experimental::IntraProcessManager::do_intra_process_publish ( uint64_t  intra_process_publisher_id,
std::unique_ptr< MessageT, Deleter >  message,
std::shared_ptr< typename allocator::AllocRebind< MessageT, Alloc >::allocator_type >  allocator 
)
inline

Publishes an intra-process message, passed as a unique pointer.

This is one of the two methods for publishing intra-process.

Using the intra-process publisher id, a list of recipients is obtained. This list is split in half, depending whether they require ownership or not.

This particular method takes a unique pointer as input. The pointer can be promoted to a shared pointer and passed to all the subscriptions that do not require ownership. In case of subscriptions requiring ownership, the message will be copied for all of them except the last one, when ownership can be transferred.

This method can save an additional copy compared to the shared pointer one.

This method can throw an exception if the publisher id is not found or if the publisher shared_ptr given to add_publisher has gone out of scope.

This method does allocate memory.

Parameters
intra_process_publisher_idthe id of the publisher of this message.
messagethe message that is being stored.

◆ do_intra_process_publish_and_return_shared()

template<typename MessageT , typename Alloc = std::allocator<void>, typename Deleter = std::default_delete<MessageT>>
std::shared_ptr<const MessageT> rclcpp::experimental::IntraProcessManager::do_intra_process_publish_and_return_shared ( uint64_t  intra_process_publisher_id,
std::unique_ptr< MessageT, Deleter >  message,
std::shared_ptr< typename allocator::AllocRebind< MessageT, Alloc >::allocator_type >  allocator 
)
inline

◆ matches_any_publishers()

bool rclcpp::experimental::IntraProcessManager::matches_any_publishers ( const rmw_gid_t id) const

Return true if the given rmw_gid_t matches any stored Publishers.

◆ get_subscription_count()

size_t rclcpp::experimental::IntraProcessManager::get_subscription_count ( uint64_t  intra_process_publisher_id) const

Return the number of intraprocess subscriptions that are matched with a given publisher id.

◆ get_subscription_intra_process()

rclcpp::experimental::SubscriptionIntraProcessBase::SharedPtr rclcpp::experimental::IntraProcessManager::get_subscription_intra_process ( uint64_t  intra_process_subscription_id)

The documentation for this class was generated from the following file: