ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

To give a quick answer (even if I agree with the comments given):

explicit constructor is called (why not implicitly ?)

I would suggest you to read about this keyword: http://en.cppreference.com/w/cpp/language/explicit

Here why an "auto" specifier is used ?

Auto is used to avoid specifying the type of _handle_add_two_ints_ as it can be found at compile time. If you wish, you can find the type and replace auto.

What does this exactly means?

It will call the function _rcutils_cli_option_exist_ and look if the user specified the option '-h' when calling the binary. If yes, print how to use the binary. Check https://github.com/ros2/rcutils/blob/1e4fd214ce20572d225e1ac2a7457dabdba26c5b/src/cmdline_parser.c

auto service_name = std::string("add_two_ints"); //naming the service ?

Is declaring a string which will be used to name the service

if (rcutils_cli_option_exist(argv, argv + argc, "-s")) {

If the '-s' option has been specified, then the user gave a service name, so _rcutils_cli_get_option_ will return the argument specified after '-s'

auto node = std::make_shared<servernode>(service_name); //passing the service name to the node ?

This create an instance of the class ServerNode with the service_name as argument.

rclcpp::spin(node);

Process any event from the node ( if a request to the service occures as example)