4.1. Factory

class eprosima::is::sh::ros2::Factory

This is a singleton class that allows to gain access to the specific publisher, subscriber, client and server conversion functions, callbacks and other tasks, for each topic and service type.

Coming from the ROS 2 msg and srv files, the Integration Service rosidl plugin will generate the conversion library files for each of them, after calling the ìs_ros2_rosidl_mix macro in the CMakeLists.txt file of the ros2_mix_generator CMake project.

The generated conversion files will be compiled into a dynamic library that will be registered to a mix file, using the is::core::MiddlewareInterfaceExtension API provided by the Integration Service Core. This ROS 2 conversion mix libraries will use this Factory class to register the conversion functions from/to ROS 2 types to xTypes, as well as the subscription, publisher, service server and service client factories, that will be used later to create the necessary links in the core to bridge ROS 2 with another middleware supported by the Integration Service.

Public Types

using RegisterTypeToFactory = std::function<xtypes::DynamicType::Ptr()>

Signature for the method that will be used to register a dynamic type within the types factory.

using RegisterSubscriptionToFactory = std::function<std::shared_ptr<void>(rclcpp::Node &node, const std::string &topic_name, const xtypes::DynamicType &message_type, TopicSubscriberSystem::SubscriptionCallback *callback, const rmw_qos_profile_t &qos_profile)>

Signature for the method that will be used to create a ROS 2 subscription to a certain topic, within the subscriptions factory.

It allows to specify the associated ROS 2 node, the topic name and type, as well as the callback function called every time a new message data arrives to this subscription.

This Factory method returns an opaque pointer containing the subscription object created by the Integration Service to manage a subscription. This subscription object is dependent on every ROS 2 type and it is autogenerated in the template available in resources/convert__msg.cpp.em and resources/convert__msg.hpp.em.

using RegisterPublisherToFactory = std::function<std::shared_ptr<TopicPublisher>(rclcpp::Node &node, const std::string &topic_name, const rmw_qos_profile_t &qos_profile)>

Signature for the method that will be used to create a ROS 2 publisher to a certain topic, within the publishers factory.

It allows to specify the associated ROS 2 node, the topic name to publish to, and the QoS profile for the publisher.

This Factory method returns a pointer to an Integration Service TopicPublisher object, holding the created ROS 2 publisher. This publisher object is dependent on every ROS 2 type and it is autogenerated in the template available in resources/convert__msg.cpp.em and resources/convert__msg.hpp.em.

using RegisterServiceClientToFactory = std::function<std::shared_ptr<ServiceClient>(rclcpp::Node &node, const std::string &service_name, ServiceClientSystem::RequestCallback *callback, const rmw_qos_profile_t &qos_profile)>

Signature for the method that will be used to create a ROS 2 service client to a certain service, within the service clients factory.

It allows to specify the associated ROS 2 node, the service name, as well as the callback function called every time a new request data arrives to this service client.

This Factory method returns a pointer containing the Integration Service ServiceClient object created by the Integration Service to manage a service client. This service client object is dependent on every ROS 2 type and it is autogenerated in the template available in resources/convert__srv.cpp.em.

using RegisterServiceProviderToFactory = std::function<std::shared_ptr<ServiceProvider>(rclcpp::Node &node, const std::string &service_name, const rmw_qos_profile_t &qos_profile)>

Signature for the method that will be used to create a ROS 2 service server to a certain service, within the service servers factory.

It allows to specify the associated ROS 2 node and the service name.

This Factory method returns a pointer containing the Integration Service ServiceProvider object created by the Integration Service to manage a service server. This service server object is dependent on every ROS 2 type and it is autogenerated in the template available in resources/convert__srv.cpp.em.

Public Functions

void register_type_factory(const std::string &type_name, RegisterTypeToFactory register_type_func)

Register a dynamic type within the types Factory.

Parameters
  • [in] type_name: The type name, used as key in the Factory types map.

  • [in] register_type_func: The function used to create the type.

xtypes::DynamicType::Ptr create_type(const std::string &type_name)

Create a dynamic type instance using the types registered previously in the Factory.

Return

A pointer to the created type, or nullptr if the type was not registered in the Factory.

Parameters
  • [in] type_name: The name of the type to be created.

void register_subscription_factory(const std::string &topic_type, RegisterSubscriptionToFactory register_sub_func)

Register a ROS 2 subscription builder within the Factory.

Parameters
  • [in] topic_type: The name of the topic type, used to index the subscription factory map.

  • [in] register_sub_func: The function used to create the subscription.

std::shared_ptr<void> create_subscription(const xtypes::DynamicType &topic_type, rclcpp::Node &node, const std::string &topic_name, TopicSubscriberSystem::SubscriptionCallback *callback, const rmw_qos_profile_t &qos_profile)

Create a ROS 2 subscription handler for the Integration Service, using the subscriptions registered previously in the Factory.

Return

An opaque pointer to the created Integration Service subscription entity.

Parameters
  • [in] topic_type: A reference to the dynamic type representation of the topic type.

  • [in] node: The ROS 2 node that will hold this subscription.

  • [in] topic_name: The topic name to be subscribed to.

  • [in] callback: The callback function called every time the ROS 2 subscription receives a new data.

  • [in] qos_profile: The QoS used to create the subscription.

void register_publisher_factory(const std::string &topic_type, RegisterPublisherToFactory register_pub_func)

Register a ROS 2 publisher builder within the Factory.

Parameters
  • [in] topic_type: The name of the topic type, used to index the publisher factory map.

  • [in] register_pub_func: The function used to create the publisher.

std::shared_ptr<TopicPublisher> create_publisher(const xtypes::DynamicType &topic_type, rclcpp::Node &node, const std::string &topic_name, const rmw_qos_profile_t &qos_profile)

Create a ROS 2 publisher handler for the Integration Service, using the publisher registered previously in the Factory.

Return

A pointer to the created Integration Service TopicPublisher entity.

Parameters
  • [in] topic_type: A reference to the dynamic type representation of the topic type.

  • [in] node: The ROS 2 node that will hold this publisher.

  • [in] topic_name: The topic name to publish to.

  • [in] qos_profile: The QoS used to create the publisher.

void register_client_proxy_factory(const std::string &service_response_type, RegisterServiceClientToFactory register_service_client_func)

Register a ROS 2 service client builder within the Factory.

Parameters
  • [in] service_response_type: The name of the service response type, used as index in the service client factory map.

  • [in] register_service_client_func: The function used to create the service client.

std::shared_ptr<ServiceClient> create_client_proxy(const std::string &service_response_type, rclcpp::Node &node, const std::string &service_name, ServiceClientSystem::RequestCallback *callback, const rmw_qos_profile_t &qos_profile)

Create a ROS 2 service client handler for the Integration Service, using the service client registered previously in the Factory.

Return

A pointer to the created Integration Service ServiceClient entity.

Parameters
  • [in] service_response_type: A reference to the dynamic type representation of the service response type.

  • [in] node: The ROS 2 node that will hold this service client.

  • [in] service_name: The service name to forward petitions to.

  • [in] callback: The callback function called every time the ROS 2 service client receives a new request.

  • [in] qos_profile: The QoS used to create the service client.

void register_server_proxy_factory(const std::string &service_request_type, RegisterServiceProviderToFactory register_service_server_func)

Register a ROS 2 service server builder within the Factory.

Parameters
  • [in] service_request_type: The name of the service server type to be registered.

  • [in] register_service_server_func: The function used to create the service server.

std::shared_ptr<ServiceProvider> create_server_proxy(const std::string &service_request_type, rclcpp::Node &node, const std::string &service_name, const rmw_qos_profile_t &qos_profile)

Create a ROS 2 service server handler for the Integration Service, using the service server registered previously in the Factory.

Return

A pointer to the created Integration Service ServiceProvider entity.

Parameters
  • [in] service_request_type: A reference to the dynamic type representation of the service request type.

  • [in] node: The ROS 2 node that will hold this service server.

  • [in] service_name: The service name to process petitions from.

  • [in] qos_profile: The QoS used to create the service server.

Public Static Functions

Factory &instance()

Get a reference to the singleton instance of this Factory.

Return

A mutable reference to the Factory singleton object instance.

class Implementation

Defines the actual implementation of the Factory class.

Allows to use the pimpl procedure to separate the implementation from the interface of Factory.

Methods named equal to some Factory method will not be documented again. Usually, the interface class will call _pimpl->method(), but the functionality and parameters are exactly the same.