Skip to content

Commit

Permalink
Switch Client constructor to use std::string.
Browse files Browse the repository at this point in the history
This make it more similar to the Service constructor.
Also make both of them use const std::string & to
avoid a copy.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Feb 21, 2023
1 parent 29da63f commit 9426838
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions rclpy/src/rclpy/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Client::destroy()
}

Client::Client(
Node & node, py::object pysrv_type, const char * service_name, py::object pyqos_profile)
Node & node, py::object pysrv_type, const std::string & service_name, py::object pyqos_profile)
: node_(node)
{
auto srv_type = static_cast<rosidl_service_type_support_t *>(
Expand Down Expand Up @@ -77,7 +77,7 @@ Client::Client(
*rcl_client_ = rcl_get_zero_initialized_client();

rcl_ret_t ret = rcl_client_init(
rcl_client_.get(), node_.rcl_ptr(), srv_type, service_name, &client_ops);
rcl_client_.get(), node_.rcl_ptr(), srv_type, service_name.c_str(), &client_ops);
if (RCL_RET_OK != ret) {
if (RCL_RET_SERVICE_NAME_INVALID == ret) {
std::string error_text{"failed to create client due to invalid service name '"};
Expand Down Expand Up @@ -150,7 +150,7 @@ void
define_client(py::object module)
{
py::class_<Client, Destroyable, std::shared_ptr<Client>>(module, "Client")
.def(py::init<Node &, py::object, const char *, py::object>())
.def(py::init<Node &, py::object, const std::string &, py::object>())
.def_property_readonly(
"pointer", [](const Client & client) {
return reinterpret_cast<size_t>(client.rcl_ptr());
Expand Down
3 changes: 2 additions & 1 deletion rclpy/src/rclpy/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <rcl/client.h>

#include <memory>
#include <string>

#include "destroyable.hpp"
#include "node.hpp"
Expand All @@ -45,7 +46,7 @@ class Client : public Destroyable, public std::enable_shared_from_this<Client>
* \param[in] service_name The service name
* \param[in] pyqos rmw_qos_profile_t object for this client
*/
Client(Node & node, py::object pysrv_type, const char * service_name, py::object pyqos);
Client(Node & node, py::object pysrv_type, const std::string & service_name, py::object pyqos);

~Client() = default;

Expand Down
7 changes: 3 additions & 4 deletions rclpy/src/rclpy/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Service::destroy()
}

Service::Service(
Node & node, py::object pysrv_type, std::string service_name,
Node & node, py::object pysrv_type, const std::string & service_name,
py::object pyqos_profile)
: node_(node)
{
Expand Down Expand Up @@ -75,8 +75,7 @@ Service::Service(
*rcl_service_ = rcl_get_zero_initialized_service();

rcl_ret_t ret = rcl_service_init(
rcl_service_.get(), node_.rcl_ptr(), srv_type,
service_name.c_str(), &service_ops);
rcl_service_.get(), node_.rcl_ptr(), srv_type, service_name.c_str(), &service_ops);
if (RCL_RET_OK != ret) {
if (ret == RCL_RET_SERVICE_NAME_INVALID) {
std::string error_text{"failed to create service due to invalid topic name '"};
Expand Down Expand Up @@ -148,7 +147,7 @@ void
define_service(py::object module)
{
py::class_<Service, Destroyable, std::shared_ptr<Service>>(module, "Service")
.def(py::init<Node &, py::object, std::string, py::object>())
.def(py::init<Node &, py::object, const std::string &, py::object>())
.def_property_readonly(
"pointer", [](const Service & service) {
return reinterpret_cast<size_t>(service.rcl_ptr());
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Service : public Destroyable, public std::enable_shared_from_this<Service>
* \return capsule containing the rcl_service_t
*/
Service(
Node & node, py::object pysrv_type, std::string service_name,
Node & node, py::object pysrv_type, const std::string & service_name,
py::object pyqos_profile);

Service(
Expand Down

0 comments on commit 9426838

Please sign in to comment.