ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
node.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 #include "rcl/node.h"
16 
17 #include <limits.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include "rcl/arguments.h"
23 #include "rcl/error_handling.h"
24 #include "rcl/init_options.h"
25 #include "rcl/localhost.h"
26 #include "rcl/logging.h"
27 #include "rcl/logging_rosout.h"
28 #include "rcl/node_type_cache.h"
29 #include "rcl/rcl.h"
30 #include "rcl/remap.h"
31 #include "rcl/security.h"
32 
33 #include "rcutils/env.h"
34 #include "rcutils/filesystem.h"
35 #include "rcutils/find.h"
36 #include "rcutils/format_string.h"
37 #include "rcutils/logging_macros.h"
38 #include "rcutils/macros.h"
39 #include "rcutils/repl_str.h"
40 #include "rcutils/snprintf.h"
41 #include "rcutils/strdup.h"
42 #include "rcutils/types/hash_map.h"
43 
44 #include "rmw/error_handling.h"
45 #include "rmw/security_options.h"
46 #include "rmw/rmw.h"
47 #include "rmw/validate_namespace.h"
48 #include "rmw/validate_node_name.h"
49 #include "rosidl_runtime_c/string_functions.h"
50 #include "rosidl_runtime_c/type_description/type_description__functions.h"
51 #include "rosidl_runtime_c/type_description/type_source__functions.h"
52 #include "tracetools/tracetools.h"
53 #include "type_description_interfaces/srv/get_type_description.h"
54 
55 #include "./context_impl.h"
56 #include "./node_impl.h"
57 
58 const char * const RCL_DISABLE_LOANED_MESSAGES_ENV_VAR = "ROS_DISABLE_LOANED_MESSAGES";
59 
61 
70 const char * rcl_create_node_logger_name(
71  const char * node_name,
72  const char * node_namespace,
73  const rcl_allocator_t * allocator)
74 {
75  // If the namespace is the root namespace ("/"), the logger name is just the node name.
76  if (strlen(node_namespace) == 1) {
77  return rcutils_strdup(node_name, *allocator);
78  }
79 
80  // Convert the forward slashes in the namespace to the separator used for logger names.
81  // The input namespace has already been expanded and therefore will always be absolute,
82  // i.e. it will start with a forward slash, which we want to ignore.
83  const char * ns_with_separators = rcutils_repl_str(
84  node_namespace + 1, // Ignore the leading forward slash.
85  "/", RCUTILS_LOGGING_SEPARATOR_STRING,
86  allocator);
87  if (NULL == ns_with_separators) {
88  return NULL;
89  }
90 
91  // Join the namespace and node name to create the logger name.
92  char * node_logger_name = rcutils_format_string(
93  *allocator, "%s%s%s", ns_with_separators, RCUTILS_LOGGING_SEPARATOR_STRING, node_name);
94  allocator->deallocate((char *)ns_with_separators, allocator->state);
95  return node_logger_name;
96 }
97 
100 {
101  static rcl_node_t null_node = {
102  .context = 0,
103  .impl = 0
104  };
105  return null_node;
106 }
107 
108 rcl_ret_t
110  rcl_node_t * node,
111  const char * name,
112  const char * namespace_,
113  rcl_context_t * context,
114  const rcl_node_options_t * options)
115 {
116  const rmw_guard_condition_t * rmw_graph_guard_condition = NULL;
117  rcl_guard_condition_options_t graph_guard_condition_options =
119  rcl_ret_t ret;
120  rcl_ret_t fail_ret = RCL_RET_ERROR;
121  char * remapped_node_name = NULL;
122  const char * local_namespace_ = NULL;
123 
124  // Check options and allocator first, so allocator can be used for errors.
125  RCL_CHECK_ARGUMENT_FOR_NULL(options, RCL_RET_INVALID_ARGUMENT);
126  const rcl_allocator_t * allocator = &options->allocator;
127  RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, "invalid allocator", return RCL_RET_INVALID_ARGUMENT);
128 
129  RCL_CHECK_ARGUMENT_FOR_NULL(name, RCL_RET_INVALID_ARGUMENT);
130  RCL_CHECK_ARGUMENT_FOR_NULL(namespace_, RCL_RET_INVALID_ARGUMENT);
131  RCL_CHECK_ARGUMENT_FOR_NULL(node, RCL_RET_INVALID_ARGUMENT);
132  RCUTILS_LOG_DEBUG_NAMED(
133  ROS_PACKAGE_NAME, "Initializing node '%s' in namespace '%s'", name, namespace_);
134  if (node->impl) {
135  RCL_SET_ERROR_MSG("node already initialized, or struct memory was unintialized");
136  return RCL_RET_ALREADY_INIT;
137  }
138  // Make sure rcl has been initialized.
139  RCL_CHECK_FOR_NULL_WITH_MSG(
140  context, "given context in options is NULL", return RCL_RET_INVALID_ARGUMENT);
141  if (!rcl_context_is_valid(context)) {
142  RCL_SET_ERROR_MSG(
143  "the given context is not valid, "
144  "either rcl_init() was not called or rcl_shutdown() was called.");
145  return RCL_RET_NOT_INIT;
146  }
147  // Make sure the node name is valid before allocating memory.
148  int validation_result = 0;
149  ret = rmw_validate_node_name(name, &validation_result, NULL);
150  if (ret != RMW_RET_OK) {
151  RCL_SET_ERROR_MSG(rmw_get_error_string().str);
152  return ret;
153  }
154  if (validation_result != RMW_NODE_NAME_VALID) {
155  const char * msg = rmw_node_name_validation_result_string(validation_result);
156  RCL_SET_ERROR_MSG(msg);
158  }
159 
160  // Process the namespace.
161  if (namespace_[0] == '\0') {
162  // If the namespace is just an empty string, replace with "/"
163  local_namespace_ = rcutils_strdup("/", *allocator);
164  } else if (namespace_[0] == '/') {
165  local_namespace_ = rcutils_strdup(namespace_, *allocator);
166  } else {
167  // If the namespace does not start with a /, add one.
168  local_namespace_ = rcutils_format_string(*allocator, "/%s", namespace_);
169  }
170  RCL_CHECK_FOR_NULL_WITH_MSG(
171  local_namespace_,
172  "failed to format node namespace string",
173  return RCL_RET_BAD_ALLOC);
174 
175  // Make sure the node namespace is valid.
176  validation_result = 0;
177  ret = rmw_validate_namespace(local_namespace_, &validation_result, NULL);
178  if (ret != RMW_RET_OK) {
179  RCL_SET_ERROR_MSG(rmw_get_error_string().str);
180  goto fail;
181  }
182  if (validation_result != RMW_NAMESPACE_VALID) {
183  const char * msg = rmw_namespace_validation_result_string(validation_result);
184  RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("%s, result: %d", msg, validation_result);
185 
187  goto fail;
188  }
189 
190  // Allocate space for the implementation struct.
191  node->impl = (rcl_node_impl_t *)allocator->zero_allocate(
192  1, sizeof(rcl_node_impl_t), allocator->state);
193  RCL_CHECK_FOR_NULL_WITH_MSG(
194  node->impl, "allocating memory failed", ret = RCL_RET_BAD_ALLOC; goto fail);
195  node->impl->options = rcl_node_get_default_options();
196  node->impl->registered_types_by_type_hash = rcutils_get_zero_initialized_hash_map();
197  node->context = context;
198  // Initialize node impl.
199  ret = rcl_node_options_copy(options, &(node->impl->options));
200  if (RCL_RET_OK != ret) {
201  goto fail;
202  }
203 
204  // Remap the node name and namespace if remap rules are given
205  rcl_arguments_t * global_args = NULL;
206  if (node->impl->options.use_global_arguments) {
207  global_args = &(node->context->global_arguments);
208  }
209  ret = rcl_remap_node_name(
210  &(node->impl->options.arguments), global_args, name, *allocator,
211  &remapped_node_name);
212  if (RCL_RET_OK != ret) {
213  goto fail;
214  }
215  if (NULL != remapped_node_name) {
216  name = remapped_node_name;
217  }
218 
219  char * remapped_namespace = NULL;
221  &(node->impl->options.arguments), global_args, name,
222  *allocator, &remapped_namespace);
223  if (RCL_RET_OK != ret) {
224  goto fail;
225  }
226  if (NULL != remapped_namespace) {
227  allocator->deallocate((char *)local_namespace_, allocator->state);
228  local_namespace_ = remapped_namespace;
229  }
230 
231  // compute fully qualfied name of the node.
232  if ('/' == local_namespace_[strlen(local_namespace_) - 1]) {
233  node->impl->fq_name = rcutils_format_string(*allocator, "%s%s", local_namespace_, name);
234  } else {
235  node->impl->fq_name = rcutils_format_string(*allocator, "%s/%s", local_namespace_, name);
236  }
237  RCL_CHECK_FOR_NULL_WITH_MSG(
238  node->impl->fq_name, "creating fully qualified name failed",
239  ret = RCL_RET_BAD_ALLOC; goto fail);
240 
241  // node logger name
242  node->impl->logger_name = rcl_create_node_logger_name(name, local_namespace_, allocator);
243  RCL_CHECK_FOR_NULL_WITH_MSG(
244  node->impl->logger_name, "creating logger name failed", ret = RCL_RET_ERROR; goto fail);
245 
246  RCUTILS_LOG_DEBUG_NAMED(
247  ROS_PACKAGE_NAME, "Using domain ID of '%zu'", context->impl->rmw_context.actual_domain_id);
248 
249  node->impl->rmw_node_handle = rmw_create_node(
250  &(node->context->impl->rmw_context),
251  name, local_namespace_);
252  RCL_CHECK_FOR_NULL_WITH_MSG(
253  node->impl->rmw_node_handle, rmw_get_error_string().str, ret = RCL_RET_ERROR; goto fail);
254 
255  // graph guard condition
256  rmw_graph_guard_condition = rmw_node_get_graph_guard_condition(node->impl->rmw_node_handle);
257  RCL_CHECK_FOR_NULL_WITH_MSG(
258  rmw_graph_guard_condition, rmw_get_error_string().str, ret = RCL_RET_ERROR; goto fail);
259 
260  node->impl->graph_guard_condition = (rcl_guard_condition_t *)allocator->allocate(
261  sizeof(rcl_guard_condition_t), allocator->state);
262  RCL_CHECK_FOR_NULL_WITH_MSG(
263  node->impl->graph_guard_condition, "allocating memory failed",
264  ret = RCL_RET_BAD_ALLOC; goto fail);
265  *node->impl->graph_guard_condition = rcl_get_zero_initialized_guard_condition();
266  graph_guard_condition_options.allocator = *allocator;
268  node->impl->graph_guard_condition,
269  rmw_graph_guard_condition,
270  context,
271  graph_guard_condition_options);
272  if (ret != RCL_RET_OK) {
273  // error message already set
274  goto fail;
275  }
276 
277  // To capture all types from builtin topics and services, the type cache needs to be initialized
278  // before any publishers/subscriptions/services/etc can be created
279  ret = rcl_node_type_cache_init(node);
280  if (ret != RCL_RET_OK) {
281  goto fail;
282  }
283 
284  RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Node initialized");
285  TRACETOOLS_TRACEPOINT(
287  (const void *)node,
288  (const void *)rcl_node_get_rmw_handle(node),
289  rcl_node_get_name(node),
290  rcl_node_get_namespace(node));
291 
292  allocator->deallocate(remapped_node_name, allocator->state);
293  allocator->deallocate((char *)local_namespace_, allocator->state);
294 
295  return RCL_RET_OK;
296 
297 fail:
298  if (node->impl) {
299  if (NULL != node->impl->registered_types_by_type_hash.impl) {
300  fail_ret = rcl_node_type_cache_fini(node);
301  RCUTILS_LOG_ERROR_EXPRESSION_NAMED(
302  (fail_ret != RCL_RET_OK),
303  ROS_PACKAGE_NAME, "Failed to fini type cache for node: %s", rcl_get_error_string().str);
304  }
305 
306  if (node->impl->graph_guard_condition) {
307  fail_ret = rcl_guard_condition_fini(node->impl->graph_guard_condition);
308  RCUTILS_LOG_ERROR_EXPRESSION_NAMED(
309  fail_ret != RCL_RET_OK, ROS_PACKAGE_NAME,
310  "failed to fini guard condition in error recovery: %s", rcl_get_error_string().str);
311 
312  allocator->deallocate(node->impl->graph_guard_condition, allocator->state);
313  }
314 
315  if (node->impl->rmw_node_handle) {
316  fail_ret = rmw_destroy_node(node->impl->rmw_node_handle);
317  RCUTILS_LOG_ERROR_EXPRESSION_NAMED(
318  fail_ret != RMW_RET_OK, ROS_PACKAGE_NAME,
319  "failed to fini rmw node in error recovery: %s", rmw_get_error_string().str);
320  }
321 
322  allocator->deallocate((char *)node->impl->logger_name, allocator->state);
323 
324  allocator->deallocate((char *)node->impl->fq_name, allocator->state);
325 
326  fail_ret = rcl_node_options_fini(&(node->impl->options));
327  RCUTILS_LOG_ERROR_EXPRESSION_NAMED(
328  fail_ret != RCL_RET_OK, ROS_PACKAGE_NAME,
329  "failed to fini node options: %s", rcl_get_error_string().str);
330 
331  allocator->deallocate(node->impl, allocator->state);
332  }
333 
334  allocator->deallocate(remapped_node_name, allocator->state);
335 
336  allocator->deallocate((char *)local_namespace_, allocator->state);
337 
339 
340  return ret;
341 }
342 
343 rcl_ret_t
345 {
346  RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Finalizing node");
347  RCL_CHECK_ARGUMENT_FOR_NULL(node, RCL_RET_NODE_INVALID);
348  if (!node->impl) {
349  // Repeat calls to fini or calling fini on a zero initialized node is ok.
350  return RCL_RET_OK;
351  }
352  rcl_allocator_t allocator = node->impl->options.allocator;
353  rcl_ret_t result = RCL_RET_OK;
354  rcl_ret_t rcl_ret = RCL_RET_OK;
355  rcl_ret = rcl_node_type_cache_fini(node);
356  if (rcl_ret != RCL_RET_OK) {
357  RCL_SET_ERROR_MSG("Unable to fini type cache for node.");
358  result = RCL_RET_ERROR;
359  }
360  rmw_ret_t rmw_ret = rmw_destroy_node(node->impl->rmw_node_handle);
361  if (rmw_ret != RMW_RET_OK) {
362  RCL_SET_ERROR_MSG(rmw_get_error_string().str);
363  result = RCL_RET_ERROR;
364  }
365  rcl_ret = rcl_guard_condition_fini(node->impl->graph_guard_condition);
366  if (rcl_ret != RCL_RET_OK) {
367  RCL_SET_ERROR_MSG(rmw_get_error_string().str);
368  result = RCL_RET_ERROR;
369  }
370  allocator.deallocate(node->impl->graph_guard_condition, allocator.state);
371  // assuming that allocate and deallocate are ok since they are checked in init
372  allocator.deallocate((char *)node->impl->logger_name, allocator.state);
373  allocator.deallocate((char *)node->impl->fq_name, allocator.state);
374  if (NULL != node->impl->options.arguments.impl) {
375  rcl_ret_t ret = rcl_arguments_fini(&(node->impl->options.arguments));
376  if (ret != RCL_RET_OK) {
377  return ret;
378  }
379  }
380  allocator.deallocate(node->impl, allocator.state);
381  node->impl = NULL;
382  RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Node finalized");
383  return result;
384 }
385 
386 bool
388 {
389  RCL_CHECK_FOR_NULL_WITH_MSG(node, "rcl node pointer is invalid", return false);
390  RCL_CHECK_FOR_NULL_WITH_MSG(node->impl, "rcl node implementation is invalid", return false);
391  RCL_CHECK_FOR_NULL_WITH_MSG(
392  node->impl->rmw_node_handle, "rcl node's rmw handle is invalid", return false);
393  return true;
394 }
395 
396 bool
398 {
399  bool result = rcl_node_is_valid_except_context(node);
400  if (!result) {
401  return result;
402  }
403  if (!rcl_context_is_valid(node->context)) {
404  RCL_SET_ERROR_MSG("rcl node's context is invalid");
405  return false;
406  }
407  return true;
408 }
409 
410 const char *
412 {
414  return NULL; // error already set
415  }
416  return node->impl->rmw_node_handle->name;
417 }
418 
419 const char *
421 {
423  return NULL; // error already set
424  }
425  return node->impl->rmw_node_handle->namespace_;
426 }
427 
428 const char *
430 {
432  return NULL; // error already set
433  }
434  return node->impl->fq_name;
435 }
436 
437 const rcl_node_options_t *
439 {
441  return NULL; // error already set
442  }
443  return &node->impl->options;
444 }
445 
446 rcl_ret_t
447 rcl_node_get_domain_id(const rcl_node_t * node, size_t * domain_id)
448 {
449  if (!rcl_node_is_valid(node)) {
450  return RCL_RET_NODE_INVALID;
451  }
452  RCL_CHECK_ARGUMENT_FOR_NULL(domain_id, RCL_RET_INVALID_ARGUMENT);
453  rcl_ret_t ret = rcl_context_get_domain_id(node->context, domain_id);
454  if (RCL_RET_OK != ret) {
455  return ret;
456  }
457  return RCL_RET_OK;
458 }
459 
460 rmw_node_t *
462 {
464  return NULL; // error already set
465  }
466  return node->impl->rmw_node_handle;
467 }
468 
469 uint64_t
471 {
473  return 0; // error already set
474  }
475  return rcl_context_get_instance_id(node->context);
476 }
477 
478 const rcl_guard_condition_t *
480 {
482  return NULL; // error already set
483  }
484  return node->impl->graph_guard_condition;
485 }
486 
487 const char *
489 {
491  return NULL; // error already set
492  }
493  return node->impl->logger_name;
494 }
495 
496 rcl_ret_t
497 rcl_get_disable_loaned_message(bool * disable_loaned_message)
498 {
499  const char * env_val = NULL;
500  const char * env_error_str = NULL;
501 
502  RCL_CHECK_ARGUMENT_FOR_NULL(disable_loaned_message, RCL_RET_INVALID_ARGUMENT);
503 
504  env_error_str = rcutils_get_env(RCL_DISABLE_LOANED_MESSAGES_ENV_VAR, &env_val);
505  if (NULL != env_error_str) {
506  RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
507  "Error getting env var: '" RCUTILS_STRINGIFY(RCL_DISABLE_LOANED_MESSAGES_ENV_VAR) "': %s\n",
508  env_error_str);
509  return RCL_RET_ERROR;
510  }
511 
512  *disable_loaned_message = (strcmp(env_val, "1") == 0);
513  return RCL_RET_OK;
514 }
515 
517  rcl_node_t * node,
518  const rmw_request_id_t * request_header,
519  const type_description_interfaces__srv__GetTypeDescription_Request * request,
520  type_description_interfaces__srv__GetTypeDescription_Response * response)
521 {
522  rcl_type_info_t type_info;
523  RCL_CHECK_FOR_NULL_WITH_MSG(node, "invalid node handle", return;);
524  RCL_CHECK_FOR_NULL_WITH_MSG(node->impl, "invalid node", return;);
525  RCL_CHECK_FOR_NULL_WITH_MSG(request_header, "invalid request header", return;);
526  RCL_CHECK_FOR_NULL_WITH_MSG(request, "null request pointer", return;);
527  RCL_CHECK_FOR_NULL_WITH_MSG(response, "null response pointer", return;);
528 
529  if (!type_description_interfaces__srv__GetTypeDescription_Response__init(response)) {
530  RCUTILS_LOG_ERROR_NAMED(
531  ROS_PACKAGE_NAME,
532  "Failed to initialize service response.");
533  return;
534  }
535  response->successful = false;
536 
537  rosidl_type_hash_t type_hash;
538  if (RCUTILS_RET_OK !=
539  rosidl_parse_type_hash_string(request->type_hash.data, &type_hash))
540  {
541  RCUTILS_LOG_ERROR_NAMED(
542  ROS_PACKAGE_NAME, "Failed to parse type hash '%s'",
543  request->type_hash.data);
544  rosidl_runtime_c__String__assign(
545  &response->failure_reason,
546  "Failed to parse type hash");
547  return;
548  }
549 
550  if (RCUTILS_RET_OK !=
551  rcl_node_type_cache_get_type_info(node, &type_hash, &type_info))
552  {
553  rosidl_runtime_c__String__assign(
554  &response->failure_reason,
555  "Type not currently in use by this node");
556  return;
557  }
558 
559  if (!type_description_interfaces__msg__TypeDescription__copy(
560  type_info.type_description, &response->type_description))
561  {
562  rosidl_runtime_c__String__assign(
563  &response->failure_reason,
564  "Failed to populate TypeDescription to response.");
565  return;
566  }
567 
568  if (request->include_type_sources) {
569  if (!type_description_interfaces__msg__TypeSource__Sequence__copy(
570  type_info.type_sources, &response->type_sources))
571  {
572  rosidl_runtime_c__String__assign(
573  &response->failure_reason,
574  "Failed to populate TypeSource_Sequence to response.");
575  return;
576  }
577  }
578 
579  response->successful = true;
580 }
581 
583  rcl_service_t * service,
584  const rcl_node_t * node)
585 {
586  RCL_CHECK_ARGUMENT_FOR_NULL(service, RCL_RET_INVALID_ARGUMENT);
587  RCL_CHECK_ARGUMENT_FOR_NULL(node, RCL_RET_INVALID_ARGUMENT);
588  RCL_CHECK_ARGUMENT_FOR_NULL(node->impl, RCL_RET_NODE_INVALID);
589 
590  if (rcl_service_is_valid(service)) {
591  return RCL_RET_ALREADY_INIT;
592  }
593  rcl_reset_error(); // Reset the error message set by rcl_service_is_valid()
594 
595  char * service_name = NULL;
596  const rosidl_service_type_support_t * type_support =
597  ROSIDL_GET_SRV_TYPE_SUPPORT(
598  type_description_interfaces, srv,
599  GetTypeDescription);
601  rcl_allocator_t allocator = node->context->impl->allocator;
602 
603  // Construct service name
605  node, "~/get_type_description",
606  allocator, true, true, &service_name);
607  if (RCL_RET_OK != ret) {
608  RCL_SET_ERROR_MSG(
609  "Failed to construct ~/get_type_description service name");
610  return ret;
611  }
612 
613  // Initialize service
614  ret = rcl_service_init(
615  service, node,
616  type_support, service_name, &service_ops);
617  allocator.deallocate(service_name, allocator.state);
618 
619  return ret;
620 }
#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
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:31
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_context_instance_id_t rcl_context_get_instance_id(const rcl_context_t *context)
Returns an unsigned integer that is unique to the given context, or 0 if invalid.
Definition: context.c:76
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_context_get_domain_id(rcl_context_t *context, size_t *domain_id)
Returns the context domain id.
Definition: context.c:83
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_context_is_valid(const rcl_context_t *context)
Return true if the given context is currently valid, otherwise false.
Definition: context.c:94
RCL_PUBLIC RCL_WARN_UNUSED rcl_guard_condition_t rcl_get_zero_initialized_guard_condition(void)
Return a rcl_guard_condition_t struct with members set to NULL.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_guard_condition_fini(rcl_guard_condition_t *guard_condition)
Finalize a rcl_guard_condition_t.
RCL_PUBLIC RCL_WARN_UNUSED rcl_guard_condition_options_t rcl_guard_condition_get_default_options(void)
Return the default options in a rcl_guard_condition_options_t struct.
rcl_ret_t rcl_guard_condition_init_from_rmw(rcl_guard_condition_t *guard_condition, const rmw_guard_condition_t *rmw_guard_condition, rcl_context_t *context, const rcl_guard_condition_options_t options)
Same as rcl_guard_condition_init(), but reusing an existing rmw handle.
RCL_PUBLIC RCL_WARN_UNUSED const rcl_node_options_t * rcl_node_get_options(const rcl_node_t *node)
Return the rcl node options.
Definition: node.c:438
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_type_description_service_init(rcl_service_t *service, const rcl_node_t *node)
Initialize the node's ~/get_type_description service.
Definition: node.c:582
RCL_PUBLIC RCL_WARN_UNUSED rcl_node_t rcl_get_zero_initialized_node(void)
Return a rcl_node_t struct with members initialized to NULL.
Definition: node.c:99
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_name(const rcl_node_t *node)
Return the name of the node.
Definition: node.c:411
RCL_PUBLIC bool rcl_node_is_valid(const rcl_node_t *node)
Return true if the node is valid, else false.
Definition: node.c:397
RCL_PUBLIC rcl_ret_t rcl_get_disable_loaned_message(bool *disable_loaned_message)
Check if loaned message is disabled, according to the environment variable.
Definition: node.c:497
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_fini(rcl_node_t *node)
Finalize a rcl_node_t.
Definition: node.c:344
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_namespace(const rcl_node_t *node)
Return the namespace of the node.
Definition: node.c:420
RCL_PUBLIC RCL_WARN_UNUSED const rcl_guard_condition_t * rcl_node_get_graph_guard_condition(const rcl_node_t *node)
Return a guard condition which is triggered when the ROS graph changes.
Definition: node.c:479
RCL_PUBLIC RCL_WARN_UNUSED rmw_node_t * rcl_node_get_rmw_handle(const rcl_node_t *node)
Return the rmw node handle.
Definition: node.c:461
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_fully_qualified_name(const rcl_node_t *node)
Return the fully qualified name of the node.
Definition: node.c:429
RCL_PUBLIC void rcl_node_type_description_service_handle_request(rcl_node_t *node, const rmw_request_id_t *request_header, const type_description_interfaces__srv__GetTypeDescription_Request *request, type_description_interfaces__srv__GetTypeDescription_Response *response)
Process a single pending request to the GetTypeDescription service.
Definition: node.c:516
RCL_PUBLIC RCL_WARN_UNUSED uint64_t rcl_node_get_rcl_instance_id(const rcl_node_t *node)
Return the associated rcl instance id.
Definition: node.c:470
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_get_domain_id(const rcl_node_t *node, size_t *domain_id)
Return the ROS domain ID that the node is using.
Definition: node.c:447
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_logger_name(const rcl_node_t *node)
Return the logger name of the node.
Definition: node.c:488
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_init(rcl_node_t *node, const char *name, const char *namespace_, rcl_context_t *context, const rcl_node_options_t *options)
Initialize a ROS node.
Definition: node.c:109
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_resolve_name(const rcl_node_t *node, const char *input_name, rcl_allocator_t allocator, bool is_service, bool only_expand, char **output_name)
Expand a given name into a fully-qualified topic name and apply remapping rules.
RCL_PUBLIC bool rcl_node_is_valid_except_context(const rcl_node_t *node)
Return true if node is valid, except for the context being valid.
Definition: node.c:387
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_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_node_namespace(const rcl_arguments_t *local_arguments, const rcl_arguments_t *global_arguments, const char *node_name, rcl_allocator_t allocator, char **output_namespace)
Remap a namespace based on given rules.
Definition: remap.c:314
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_node_name(const rcl_arguments_t *local_arguments, const rcl_arguments_t *global_arguments, const char *node_name, rcl_allocator_t allocator, char **output_name)
Remap a node name based on given rules.
Definition: remap.c:294
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_service_init(rcl_service_t *service, const rcl_node_t *node, const rosidl_service_type_support_t *type_support, const char *service_name, const rcl_service_options_t *options)
Initialize a rcl service.
Definition: service.c:85
RCL_PUBLIC bool rcl_service_is_valid(const rcl_service_t *service)
Check that the service is valid.
Definition: service.c:424
RCL_PUBLIC RCL_WARN_UNUSED rcl_service_options_t rcl_service_get_default_options(void)
Return the default service options in a rcl_service_options_t.
Definition: service.c:285
Hold output of parsing command line arguments.
Definition: arguments.h:36
rcl_arguments_impl_t * impl
Private implementation pointer.
Definition: arguments.h:38
rmw_context_t rmw_context
rmw context.
Definition: context_impl.h:40
rcl_allocator_t allocator
Allocator used during init and shutdown.
Definition: context_impl.h:32
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:114
rcl_context_impl_t * impl
Implementation specific pointer.
Definition: context.h:120
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Definition: context.h:117
Options available for a rcl guard condition.
rcl_allocator_t allocator
Custom allocator for the guard condition, used for internal allocations.
Handle for a rcl guard condition.
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
rcl_arguments_t arguments
Command line arguments that apply only to this node.
Definition: node_options.h:50
rcl_allocator_t allocator
If true, no parameter infrastructure will be setup.
Definition: node_options.h:44
Structure which encapsulates a ROS Node.
Definition: node.h:45
rcl_node_impl_t * impl
Private implementation pointer.
Definition: node.h:50
rcl_context_t * context
Context associated with this node.
Definition: node.h:47
Options available for a rcl service.
Definition: service.h:50
Structure which encapsulates a ROS Service.
Definition: service.h:43
#define RCL_RET_NODE_INVALID_NAMESPACE
Invalid node namespace return code.
Definition: types.h:63
#define RCL_RET_NOT_INIT
rcl_init() not yet called return code.
Definition: types.h:43
#define RCL_RET_ALREADY_INIT
rcl_init() already called return code.
Definition: types.h:41
#define RCL_RET_OK
Success return code.
Definition: types.h:27
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
Definition: types.h:33
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
Definition: types.h:35
#define RCL_RET_ERROR
Unspecified error return code.
Definition: types.h:29
#define RCL_RET_NODE_INVALID
Invalid rcl_node_t given return code.
Definition: types.h:59
#define RCL_RET_NODE_INVALID_NAME
Invalid node name return code.
Definition: types.h:61
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24