3.1. Factory

class eprosima::is::sh::ros1::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 1 msg and srv files, the Integration Service genmsg plugin will generate the conversion library files for each of them, after calling the ìs_ros1_genmsg_mix macro in the CMakeLists.txt file of the ros1_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 1 conversion mix libraries will use this Factory class to register the conversion functions from/to ROS 1 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 1 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>(ros::NodeHandle &node, const std::string &topic_name, const xtypes::DynamicType &message_type, TopicSubscriberSystem::SubscriptionCallback *callback, uint32_t queue_size, const ros::TransportHints &transport_hints)>

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

It allows to specify the associated ROS 1 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 1 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>(ros::NodeHandle &node, const std::string &topic_name, uint32_t queue_size, bool latch)>

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

It allows to specify the associated ROS 1 node, the topic name to publish to, the queue size and enabling/disabling message latching.

This Factory method returns a pointer to an Integration Service TopicPublisher object, holding the created ROS 1 publisher. This publisher object is dependent on every ROS 1 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>(ros::NodeHandle &node, const std::string &service_name, ServiceClientSystem::RequestCallback *callback)>

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

It allows to specify the associated ROS 1 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 1 type and it is autogenerated in the template available in resources/convert__srv.cpp.em.

using RegisterServiceProviderToFactory = std::function<std::shared_ptr<ServiceProvider>(ros::NodeHandle &node, const std::string &service_name)>

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

It allows to specify the associated ROS 1 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 1 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 1 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, ros::NodeHandle &node, const std::string &topic_name, TopicSubscriberSystem::SubscriptionCallback *callback, uint32_t queue_size, const ros::TransportHints &transport_hints)

Create a ROS 1 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 1 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 1 subscription receives a new data.

  • [in] queue_size: The maximum message queue size for the ROS 1 subscription.

  • [in] transport_hints: Provides the subscriber with specific transport information.

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

Register a ROS 1 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, ros::NodeHandle &node, const std::string &topic_name, uint32_t queue_size, bool latch)

Create a ROS 1 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 1 node that will hold this publisher.

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

  • [in] queue_size: The maximum message queue size for the ROS 1 publisher.

  • [in] latch: Enable/disable latching. When a connection is latched, the last message published is saved and sent to any future subscribers that connect.

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

Register a ROS 1 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, ros::NodeHandle &node, const std::string &service_name, ServiceClientSystem::RequestCallback *callback)

Create a ROS 1 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 1 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 1 service client receives a new request.

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

Register a ROS 1 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, ros::NodeHandle &node, const std::string &service_name)

Create a ROS 1 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 1 node that will hold this service server.

  • [in] service_name: The name of the service.

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.