ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
node_options.c
1 // Copyright 2015 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 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 #include "rcutils/macros.h"
21 
22 #include "rcl/node_options.h"
23 
24 #include "rcl/arguments.h"
25 #include "rcl/domain_id.h"
26 #include "rcl/error_handling.h"
27 #include "rcl/logging_rosout.h"
28 
29 #include "rmw/qos_profiles.h"
30 
33 {
34  // !!! MAKE SURE THAT CHANGES TO THESE DEFAULTS ARE REFLECTED IN THE HEADER DOC STRING
35  rcl_node_options_t default_options = {
37  .use_global_arguments = true,
39  .enable_rosout = true,
40  .rosout_qos = rmw_qos_profile_rosout_default,
41  };
42  return default_options;
43 }
44 
47  const rcl_node_options_t * options,
48  rcl_node_options_t * options_out)
49 {
50  RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);
51 
52  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
53  RCL_CHECK_ARGUMENT_FOR_NULL(options_out, RCL_RET_INVALID_ARGUMENT);
54  if (options_out == options) {
55  RCL_SET_ERROR_MSG("Attempted to copy options into itself");
57  }
58  if (NULL != options_out->arguments.impl) {
59  RCL_SET_ERROR_MSG("Options out must be zero initialized");
61  }
62  options_out->allocator = options->allocator;
63  options_out->use_global_arguments = options->use_global_arguments;
64  options_out->enable_rosout = options->enable_rosout;
65  options_out->rosout_qos = options->rosout_qos;
66  if (NULL != options->arguments.impl) {
67  return rcl_arguments_copy(&(options->arguments), &(options_out->arguments));
68  }
69  return RCL_RET_OK;
70 }
71 
74  rcl_node_options_t * options)
75 {
76  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
77  rcl_allocator_t allocator = options->allocator;
79 
80  if (options->arguments.impl) {
81  rcl_ret_t ret = rcl_arguments_fini(&options->arguments);
82  if (RCL_RET_OK != ret) {
83  RCL_SET_ERROR_MSG("Failed to fini rcl arguments");
84  return ret;
85  }
86  }
87 
88  return RCL_RET_OK;
89 }
90 
91 #ifdef __cplusplus
92 }
93 #endif
#define RCL_CHECK_ALLOCATOR(allocator, fail_statement)
Check that the given allocator is initialized.
Definition: allocator.h:49
#define rcl_get_default_allocator
Return a properly initialized rcl_allocator_t with default values.
Definition: allocator.h:37
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_arguments_copy(const rcl_arguments_t *args, rcl_arguments_t *args_out)
Copy one arguments structure into another.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_arguments_fini(rcl_arguments_t *args)
Reclaim resources held inside rcl_arguments_t structure.
RCL_PUBLIC RCL_WARN_UNUSED rcl_arguments_t rcl_get_zero_initialized_arguments(void)
Return a rcl_arguments_t struct with members initialized to NULL.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_options_copy(const rcl_node_options_t *options, rcl_node_options_t *options_out)
Copy one options structure into another.
Definition: node_options.c:46
RCL_PUBLIC rcl_node_options_t rcl_node_get_default_options(void)
Return the default node options in a rcl_node_options_t.
Definition: node_options.c:32
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_options_fini(rcl_node_options_t *options)
Finalize the given node_options.
Definition: node_options.c:73
rcl_arguments_impl_t * impl
Private implementation pointer.
Definition: arguments.h:38
Structure which encapsulates the options for creating a rcl_node_t.
Definition: node_options.h:35
bool use_global_arguments
If false then only use arguments in this struct, otherwise use global arguments also.
Definition: node_options.h:47
rmw_qos_profile_t rosout_qos
Middleware quality of service settings for /rosout.
Definition: node_options.h:56
rcl_arguments_t arguments
Command line arguments that apply only to this node.
Definition: node_options.h:50
bool enable_rosout
Flag to enable rosout for this node.
Definition: node_options.h:53
rcl_allocator_t allocator
If true, no parameter infrastructure will be setup.
Definition: node_options.h:44
#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