Class ComponentManager

Inheritance Relationships

Base Type

  • public rclcpp::Node

Derived Type

Class Documentation

class ComponentManager : public rclcpp::Node

ComponentManager handles the services to load, unload, and get the list of loaded components.

Subclassed by rclcpp_components::ComponentManagerIsolated< ExecutorT >

Public Types

using LoadNode = composition_interfaces::srv::LoadNode
using UnloadNode = composition_interfaces::srv::UnloadNode
using ListNodes = composition_interfaces::srv::ListNodes
using ComponentResource = std::pair<std::string, std::string>

Represents a component resource.

Is a pair of class name (for class loader) and library path (absolute)

Public Functions

ComponentManager(std::weak_ptr<rclcpp::Executor> executor = std::weak_ptr<rclcpp::executors::MultiThreadedExecutor>(), std::string node_name = "ComponentManager", const rclcpp::NodeOptions &node_options = rclcpp::NodeOptions().start_parameter_services(false).start_parameter_event_publisher(false))

Default constructor.

Initializes the component manager. It creates the services: load node, unload node and list nodes.

Parameters:
  • executor – the executor which will spin the node.

  • node_name – the name of the node that the data originates from.

  • node_options – additional options to control creation of the node.

virtual ~ComponentManager()
virtual std::vector<ComponentResource> get_component_resources(const std::string &package_name, const std::string &resource_index = "rclcpp_components") const

Return a list of valid loadable components in a given package.

Parameters:
  • package_name – name of the package

  • resource_index – name of the executable

Throws:

ComponentManagerException – if the resource was not found or a invalid resource entry

Returns:

a list of component resources

virtual std::shared_ptr<rclcpp_components::NodeFactory> create_component_factory(const ComponentResource &resource)

Instantiate a component from a dynamic library.

Parameters:

resource – a component resource (class name + library path)

Returns:

a NodeFactory interface

virtual void set_executor(const std::weak_ptr<rclcpp::Executor> executor)

Member function to set a executor in the component.

Parameters:

executor – executor to be set

Protected Functions

virtual rclcpp::NodeOptions create_node_options(const std::shared_ptr<LoadNode::Request> request)

Create node options for loaded component.

Parameters:

request – information with the node to load

Returns:

node options

virtual void add_node_to_executor(uint64_t node_id)

Add component node to executor model, it’s invoked in on_load_node()

Parameters:

node_id – node_id of loaded component node in node_wrappers_

virtual void remove_node_from_executor(uint64_t node_id)

Remove component node from executor model, it’s invoked in on_unload_node()

Parameters:

node_id – node_id of loaded component node in node_wrappers_

virtual void on_load_node(const std::shared_ptr<rmw_request_id_t> request_header, const std::shared_ptr<LoadNode::Request> request, std::shared_ptr<LoadNode::Response> response)

Service callback to load a new node in the component.

This function allows to add parameters, remap rules, a specific node, name a namespace and/or additional arguments.

Parameters:
  • request_header – unused

  • request – information with the node to load

  • response

Throws:
  • std::overflow_error – if node_id suffers an overflow. Very unlikely to happen at 1 kHz (very optimistic rate). it would take 585 years.

  • ComponentManagerException – In the case that the component constructor throws an exception, rethrow into the following catch block.

virtual void on_unload_node(const std::shared_ptr<rmw_request_id_t> request_header, const std::shared_ptr<UnloadNode::Request> request, std::shared_ptr<UnloadNode::Response> response)

Service callback to unload a node in the component.

Parameters:
  • request_header – unused

  • request – unique identifier to remove from the component

  • response – true on the success field if the node unload was succefully, otherwise false and the error_message field contains the error.

virtual void on_list_nodes(const std::shared_ptr<rmw_request_id_t> request_header, const std::shared_ptr<ListNodes::Request> request, std::shared_ptr<ListNodes::Response> response)

Service callback to get the list of nodes in the component.

Return a two list: one with the unique identifiers and other with full name of the nodes.

Parameters:
  • request_header – unused

  • request – unused

  • response – list with the unique ids and full node names

Protected Attributes

std::weak_ptr<rclcpp::Executor> executor_
uint64_t unique_id_ = {1}
std::map<std::string, std::unique_ptr<class_loader::ClassLoader>> loaders_
std::map<uint64_t, rclcpp_components::NodeInstanceWrapper> node_wrappers_
rclcpp::Service<LoadNode>::SharedPtr loadNode_srv_
rclcpp::Service<UnloadNode>::SharedPtr unloadNode_srv_
rclcpp::Service<ListNodes>::SharedPtr listNodes_srv_