ROS 2 rclcpp + rcl - humble  humble
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 
31 {
32  // !!! MAKE SURE THAT CHANGES TO THESE DEFAULTS ARE REFLECTED IN THE HEADER DOC STRING
33  rcl_node_options_t default_options = {
35  .use_global_arguments = true,
37  .enable_rosout = true,
38  .rosout_qos = rcl_qos_profile_rosout_default,
39  };
40  return default_options;
41 }
42 
45  const rcl_node_options_t * options,
46  rcl_node_options_t * options_out)
47 {
48  RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);
49 
50  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
51  RCL_CHECK_ARGUMENT_FOR_NULL(options_out, RCL_RET_INVALID_ARGUMENT);
52  if (options_out == options) {
53  RCL_SET_ERROR_MSG("Attempted to copy options into itself");
55  }
56  if (NULL != options_out->arguments.impl) {
57  RCL_SET_ERROR_MSG("Options out must be zero initialized");
59  }
60  options_out->allocator = options->allocator;
61  options_out->use_global_arguments = options->use_global_arguments;
62  options_out->enable_rosout = options->enable_rosout;
63  options_out->rosout_qos = options->rosout_qos;
64  if (NULL != options->arguments.impl) {
65  return rcl_arguments_copy(&(options->arguments), &(options_out->arguments));
66  }
67  return RCL_RET_OK;
68 }
69 
72  rcl_node_options_t * options)
73 {
74  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
75  rcl_allocator_t allocator = options->allocator;
77 
78  if (options->arguments.impl) {
79  rcl_ret_t ret = rcl_arguments_fini(&options->arguments);
80  if (RCL_RET_OK != ret) {
81  RCL_SET_ERROR_MSG("Failed to fini rcl arguments");
82  return ret;
83  }
84  }
85 
86  return RCL_RET_OK;
87 }
88 
89 #ifdef __cplusplus
90 }
91 #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:44
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:30
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:71
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: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