ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
network_flow_endpoints.c
1 // Copyright 2020 Ericsson AB
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 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 #include "rcl/error_handling.h"
21 #include "rcl/graph.h"
22 #include "rcl/network_flow_endpoints.h"
23 #include "rcl/publisher.h"
24 #include "rcl/subscription.h"
25 
26 #include "rcutils/allocator.h"
27 #include "rcutils/macros.h"
28 #include "rcutils/types.h"
29 
30 #include "rmw/error_handling.h"
31 #include "rmw/get_network_flow_endpoints.h"
32 #include "rmw/network_flow_endpoint_array.h"
33 #include "rmw/types.h"
34 
35 #include "./common.h"
36 
38 __validate_network_flow_endpoint_array(
39  rcl_network_flow_endpoint_array_t * network_flow_endpoint_array)
40 {
41  RCL_CHECK_ARGUMENT_FOR_NULL(network_flow_endpoint_array, RCL_RET_INVALID_ARGUMENT);
42 
43  rmw_error_string_t error_string;
44  rmw_ret_t rmw_ret = rmw_network_flow_endpoint_array_check_zero(network_flow_endpoint_array);
45  if (rmw_ret != RMW_RET_OK) {
46  error_string = rmw_get_error_string();
47  rmw_reset_error();
48  RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
49  "rcl_network_flow_endpoint_array_t must be zero initialized: %s,\n"
50  "Use rcl_get_zero_initialized_network_flow_endpoint_array",
51  error_string.str);
52  }
53 
54  return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
55 }
56 
58 rcl_publisher_get_network_flow_endpoints(
59  const rcl_publisher_t * publisher,
60  rcutils_allocator_t * allocator,
61  rcl_network_flow_endpoint_array_t * network_flow_endpoint_array)
62 {
63  if (!rcl_publisher_is_valid(publisher)) {
65  }
66 
67  RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
68 
69  rcl_ret_t rcl_ret = __validate_network_flow_endpoint_array(
70  network_flow_endpoint_array);
71  if (rcl_ret != RCL_RET_OK) {
72  return rcl_ret;
73  }
74 
75  rmw_error_string_t error_string;
76  rmw_ret_t rmw_ret = rmw_publisher_get_network_flow_endpoints(
78  allocator,
79  network_flow_endpoint_array);
80  if (rmw_ret != RMW_RET_OK) {
81  error_string = rmw_get_error_string();
82  rmw_reset_error();
83  RCL_SET_ERROR_MSG(error_string.str);
84  }
85  return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
86 }
87 
89 rcl_subscription_get_network_flow_endpoints(
90  const rcl_subscription_t * subscription,
91  rcutils_allocator_t * allocator,
92  rcl_network_flow_endpoint_array_t * network_flow_endpoint_array)
93 {
94  if (!rcl_subscription_is_valid(subscription)) {
96  }
97 
98  RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
99 
100  rcl_ret_t rcl_ret = __validate_network_flow_endpoint_array(
101  network_flow_endpoint_array);
102  if (rcl_ret != RCL_RET_OK) {
103  return rcl_ret;
104  }
105 
106  rmw_error_string_t error_string;
107  rmw_ret_t rmw_ret = rmw_subscription_get_network_flow_endpoints(
108  rcl_subscription_get_rmw_handle(subscription),
109  allocator,
110  network_flow_endpoint_array);
111  if (rmw_ret != RMW_RET_OK) {
112  error_string = rmw_get_error_string();
113  rmw_reset_error();
114  RCL_SET_ERROR_MSG(error_string.str);
115  }
116  return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
117 }
118 
119 #ifdef __cplusplus
120 }
121 #endif
#define RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, msg, fail_statement)
Check that the given allocator is initialized, or fail with a message.
Definition: allocator.h:56
RCL_PUBLIC bool rcl_publisher_is_valid(const rcl_publisher_t *publisher)
Return true if the publisher is valid, otherwise false.
Definition: publisher.c:383
RCL_PUBLIC RCL_WARN_UNUSED rmw_publisher_t * rcl_publisher_get_rmw_handle(const rcl_publisher_t *publisher)
Return the rmw publisher handle.
Definition: publisher.c:365
Structure which encapsulates a ROS Publisher.
Definition: publisher.h:37
Structure which encapsulates a ROS Subscription.
Definition: subscription.h:39
RCL_PUBLIC RCL_WARN_UNUSED rmw_subscription_t * rcl_subscription_get_rmw_handle(const rcl_subscription_t *subscription)
Return the rmw subscription handle.
Definition: subscription.c:683
RCL_PUBLIC bool rcl_subscription_is_valid(const rcl_subscription_t *subscription)
Check that the subscription is valid.
Definition: subscription.c:692
#define RCL_RET_OK
Success return code.
Definition: types.h:26
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: types.h:34
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:23