ROS 2 rclcpp + rcl - rolling  rolling-e7363f10
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 <stdbool.h>
21 #include <stddef.h>
22 
23 #include "rcl/node_options.h"
24 
25 #include "rcl/allocator.h"
26 #include "rcl/arguments.h"
27 #include "rcl/domain_id.h"
28 #include "rcl/error_handling.h"
29 #include "rcl/logging_rosout.h"
30 #include "rcl/types.h"
31 
32 #include "rmw/qos_profiles.h"
33 
36 {
37  // !!! MAKE SURE THAT CHANGES TO THESE DEFAULTS ARE REFLECTED IN THE HEADER DOC STRING
38  rcl_node_options_t default_options = {
40  .use_global_arguments = true,
42  .enable_rosout = true,
43  .rosout_qos = rmw_qos_profile_rosout_default,
44  };
45  return default_options;
46 }
47 
50  const rcl_node_options_t * options,
51  rcl_node_options_t * options_out)
52 {
53  RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);
54 
55  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
56  RCL_CHECK_ARGUMENT_FOR_NULL(options_out, RCL_RET_INVALID_ARGUMENT);
57  if (options_out == options) {
58  RCL_SET_ERROR_MSG("Attempted to copy options into itself");
60  }
61  if (NULL != options_out->arguments.impl) {
62  RCL_SET_ERROR_MSG("Options out must be zero initialized");
64  }
65  options_out->allocator = options->allocator;
66  options_out->use_global_arguments = options->use_global_arguments;
67  options_out->enable_rosout = options->enable_rosout;
68  options_out->rosout_qos = options->rosout_qos;
69  if (NULL != options->arguments.impl) {
70  return rcl_arguments_copy(&(options->arguments), &(options_out->arguments));
71  }
72  return RCL_RET_OK;
73 }
74 
77  rcl_node_options_t * options)
78 {
79  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
80  rcl_allocator_t allocator = options->allocator;
82 
83  if (options->arguments.impl) {
84  rcl_ret_t ret = rcl_arguments_fini(&options->arguments);
85  if (RCL_RET_OK != ret) {
86  RCL_SET_ERROR_MSG("Failed to fini rcl arguments");
87  return ret;
88  }
89  }
90 
91  return RCL_RET_OK;
92 }
93 
94 #ifdef __cplusplus
95 }
96 #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:49
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:35
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:76
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:41
bool use_global_arguments
If false then only use arguments in this struct, otherwise use global arguments also.
Definition: node_options.h:53
rmw_qos_profile_t rosout_qos
Middleware quality of service settings for /rosout.
Definition: node_options.h:62
rcl_arguments_t arguments
Command line arguments that apply only to this node.
Definition: node_options.h:56
bool enable_rosout
Flag to enable rosout for this node.
Definition: node_options.h:59
rcl_allocator_t allocator
If true, no parameter infrastructure will be setup.
Definition: node_options.h:50
#define RCL_RET_OK
Success return code.
Definition: types.h:28
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: types.h:36
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:25