ROS 2 rclcpp + rcl - rolling  rolling-e7363f10
ROS 2 C++ Client Library with ROS Client Library
context.h
Go to the documentation of this file.
1 // Copyright 2018 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 
16 
17 #ifndef RCL__CONTEXT_H_
18 #define RCL__CONTEXT_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <stdbool.h>
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #include "rmw/init.h"
30 
31 #include "rcl/arguments.h"
32 #include "rcl/init_options.h"
33 #include "rcl/macros.h"
34 #include "rcl/types.h"
35 #include "rcl/visibility_control.h"
36 
38 #ifdef _MSC_VER
39 #define RCL_ALIGNAS(N) __declspec(align(N))
40 #else
41 #include <stdalign.h>
42 #define RCL_ALIGNAS(N) alignas(N)
43 #endif
45 
47 typedef uint64_t rcl_context_instance_id_t;
48 
50 
52 
116 typedef struct rcl_context_s
117 {
119 
121 
124 
125  // The assumption that this is big enough for an atomic_uint_least64_t is
126  // ensured with a static_assert in the context.c file.
127  // In most cases it should just be a plain uint64_t.
129 #if !defined(RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE)
130 #define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE sizeof(uint_least64_t)
131 #endif
134 
152  RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE];
154 
156 RCL_PUBLIC
157 RCL_WARN_UNUSED
160 
162 
185 RCL_PUBLIC
186 RCL_WARN_UNUSED
187 rcl_ret_t
189 
191 
217 RCL_PUBLIC
218 RCL_WARN_UNUSED
219 const rcl_init_options_t *
221 
223 
245 RCL_PUBLIC
246 RCL_WARN_UNUSED
249 
251 
271 RCL_PUBLIC
272 RCL_WARN_UNUSED
273 rcl_ret_t
274 rcl_context_get_domain_id(rcl_context_t * context, size_t * domain_id);
275 
277 
293 RCL_PUBLIC
294 RCL_WARN_UNUSED
295 bool
296 rcl_context_is_valid(const rcl_context_t * context);
297 
299 
315 RCL_PUBLIC
316 RCL_WARN_UNUSED
317 rmw_context_t *
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 
324 #endif // RCL__CONTEXT_H_
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:88
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_context_fini(rcl_context_t *context)
Finalize a context.
Definition: context.c:61
RCL_PUBLIC RCL_WARN_UNUSED const rcl_init_options_t * rcl_context_get_init_options(const rcl_context_t *context)
Return the init options used during initialization for this context.
Definition: context.c:80
RCL_PUBLIC RCL_WARN_UNUSED rmw_context_t * rcl_context_get_rmw_context(rcl_context_t *context)
Return pointer to the rmw context if the given context is currently valid, otherwise NULL.
Definition: context.c:113
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:95
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:106
RCL_PUBLIC RCL_WARN_UNUSED rcl_context_t rcl_get_zero_initialized_context(void)
Return a zero initialization context object.
Definition: context.c:41
uint64_t rcl_context_instance_id_t
A unique ID per context instance.
Definition: context.h:47
Hold output of parsing command line arguments.
Definition: arguments.h:36
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:117
rcl_context_impl_t * impl
Implementation specific pointer.
Definition: context.h:123
RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]
Private storage for instance ID atomic.
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Definition: context.h:120
Encapsulation of init options and implementation defined init options.
Definition: init_options.h:38
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:25