ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
localhost.c
1 // Copyright 2019 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "rcl/localhost.h"
16 
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include "rcutils/env.h"
21 
22 #include "rcl/error_handling.h"
23 #include "rcl/types.h"
24 
25 const char * const RCL_LOCALHOST_ENV_VAR = "ROS_LOCALHOST_ONLY";
26 
28 rcl_get_localhost_only(rmw_localhost_only_t * localhost_only)
29 {
30  const char * ros_local_host_env_val = NULL;
31  const char * get_env_error_str = NULL;
32 
33  RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);
34  RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_ERROR);
35  RCL_CHECK_ARGUMENT_FOR_NULL(localhost_only, RCL_RET_INVALID_ARGUMENT);
36 
37  get_env_error_str = rcutils_get_env(RCL_LOCALHOST_ENV_VAR, &ros_local_host_env_val);
38  if (NULL != get_env_error_str) {
39  RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
40  "Error getting env var '" RCUTILS_STRINGIFY(RCL_LOCALHOST_ENV_VAR) "': %s\n",
41  get_env_error_str);
42  return RCL_RET_ERROR;
43  }
44  *localhost_only = (ros_local_host_env_val != NULL &&
45  strcmp(
46  ros_local_host_env_val,
47  "1") == 0) ? RMW_LOCALHOST_ONLY_ENABLED : RMW_LOCALHOST_ONLY_DISABLED;
48  return RCL_RET_OK;
49 }
RCL_PUBLIC rcl_ret_t rcl_get_localhost_only(rmw_localhost_only_t *localhost_only)
Determine if the user wants to communicate using loopback only.
Definition: localhost.c:28
#define RCL_RET_OK
Success return code.
Definition: types.h:26
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: types.h:34
#define RCL_RET_ERROR
Unspecified error return code.
Definition: types.h:28
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:23