ROS 2 rclcpp + rcl - kilted  kilted
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 #include "rcl/error_handling.h"
16 #include "rcl/graph.h"
17 #include "rcl/network_flow_endpoints.h"
18 #include "rcl/publisher.h"
19 #include "rcl/subscription.h"
20 
21 #include "rcutils/allocator.h"
22 #include "rcutils/macros.h"
23 #include "rcutils/types.h"
24 
25 #include "rmw/error_handling.h"
26 #include "rmw/get_network_flow_endpoints.h"
27 #include "rmw/network_flow_endpoint_array.h"
28 #include "rmw/types.h"
29 
30 #include "./common.h"
31 
33 __validate_network_flow_endpoint_array(
34  rcl_network_flow_endpoint_array_t * network_flow_endpoint_array)
35 {
36  RCL_CHECK_ARGUMENT_FOR_NULL(network_flow_endpoint_array, RCL_RET_INVALID_ARGUMENT);
37 
38  rmw_error_string_t error_string;
39  rmw_ret_t rmw_ret = rmw_network_flow_endpoint_array_check_zero(network_flow_endpoint_array);
40  if (rmw_ret != RMW_RET_OK) {
41  error_string = rmw_get_error_string();
42  rmw_reset_error();
43  RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
44  "rcl_network_flow_endpoint_array_t must be zero initialized: %s,\n"
45  "Use rcl_get_zero_initialized_network_flow_endpoint_array",
46  error_string.str);
47  }
48 
49  return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
50 }
51 
53 rcl_publisher_get_network_flow_endpoints(
54  const rcl_publisher_t * publisher,
55  rcutils_allocator_t * allocator,
56  rcl_network_flow_endpoint_array_t * network_flow_endpoint_array)
57 {
58  if (!rcl_publisher_is_valid(publisher)) {
60  }
61 
62  RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
63 
64  rcl_ret_t rcl_ret = __validate_network_flow_endpoint_array(
65  network_flow_endpoint_array);
66  if (rcl_ret != RCL_RET_OK) {
67  return rcl_ret;
68  }
69 
70  rmw_error_string_t error_string;
71  rmw_ret_t rmw_ret = rmw_publisher_get_network_flow_endpoints(
73  allocator,
74  network_flow_endpoint_array);
75  if (rmw_ret != RMW_RET_OK) {
76  error_string = rmw_get_error_string();
77  rmw_reset_error();
78  RCL_SET_ERROR_MSG(error_string.str);
79  }
80  return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
81 }
82 
84 rcl_subscription_get_network_flow_endpoints(
85  const rcl_subscription_t * subscription,
86  rcutils_allocator_t * allocator,
87  rcl_network_flow_endpoint_array_t * network_flow_endpoint_array)
88 {
89  if (!rcl_subscription_is_valid(subscription)) {
91  }
92 
93  RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
94 
95  rcl_ret_t rcl_ret = __validate_network_flow_endpoint_array(
96  network_flow_endpoint_array);
97  if (rcl_ret != RCL_RET_OK) {
98  return rcl_ret;
99  }
100 
101  rmw_error_string_t error_string;
102  rmw_ret_t rmw_ret = rmw_subscription_get_network_flow_endpoints(
103  rcl_subscription_get_rmw_handle(subscription),
104  allocator,
105  network_flow_endpoint_array);
106  if (rmw_ret != RMW_RET_OK) {
107  error_string = rmw_get_error_string();
108  rmw_reset_error();
109  RCL_SET_ERROR_MSG(error_string.str);
110  }
111  return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
112 }
#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:418
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:400
Structure which encapsulates a ROS Publisher.
Definition: publisher.h:37
Structure which encapsulates a ROS Subscription.
Definition: subscription.h:40
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:758
RCL_PUBLIC bool rcl_subscription_is_valid(const rcl_subscription_t *subscription)
Check that the subscription is valid.
Definition: subscription.c:767
#define RCL_RET_OK
Success return code.
Definition: types.h:27
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: types.h:35
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24