rcl  master
C API providing common ROS client library functionality.
context.h
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 
15 #ifndef RCL__CONTEXT_H_
16 #define RCL__CONTEXT_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include "rmw/init.h"
24 
25 #include "rcl/allocator.h"
26 #include "rcl/arguments.h"
27 #include "rcl/init_options.h"
28 #include "rcl/macros.h"
29 #include "rcl/types.h"
30 #include "rcl/visibility_control.h"
31 
32 #ifdef _MSC_VER
33 #define RCL_ALIGNAS(N) __declspec(align(N))
34 #else
35 #include <stdalign.h>
36 #define RCL_ALIGNAS(N) alignas(N)
37 #endif
38 
39 typedef uint64_t rcl_context_instance_id_t;
40 
41 struct rcl_context_impl_t;
42 
44 
108 typedef struct rcl_context_t
109 {
111 
113 
115  struct rcl_context_impl_t * impl;
116 
117  // The assumption that this is big enough for an atomic_uint_least64_t is
118  // ensured with a static_assert in the context.c file.
119  // In most cases it should just be a plain uint64_t.
120 #if !defined(RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE)
121 #define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE sizeof(uint_least64_t)
122 #endif
123 
142  RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE];
143 } rcl_context_t;
144 
146 RCL_PUBLIC
147 RCL_WARN_UNUSED
149 rcl_get_zero_initialized_context(void);
150 
151 // See `rcl_init()` for initialization of the context.
152 
154 
176 RCL_PUBLIC
177 RCL_WARN_UNUSED
178 rcl_ret_t
179 rcl_context_fini(rcl_context_t * context);
180 
181 // See `rcl_shutdown()` for invalidation of the context.
182 
184 
210 RCL_PUBLIC
211 RCL_WARN_UNUSED
212 const rcl_init_options_t *
213 rcl_context_get_init_options(rcl_context_t * context);
214 
216 
238 RCL_PUBLIC
239 RCL_WARN_UNUSED
240 rcl_context_instance_id_t
241 rcl_context_get_instance_id(rcl_context_t * context);
242 
244 
260 RCL_PUBLIC
261 RCL_WARN_UNUSED
262 bool
263 rcl_context_is_valid(rcl_context_t * context);
264 
266 
282 RCL_PUBLIC
283 RCL_WARN_UNUSED
285 rcl_context_get_rmw_context(rcl_context_t * context);
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif // RCL__CONTEXT_H_
rcl_context_t::global_arguments
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Definition: context.h:112
rcl_context_t::impl
struct rcl_context_impl_t * impl
Implementation specific pointer.
Definition: context.h:115
init.h
rcl_init_options_t
Encapsulation of init options and implementation defined init options.
Definition: init_options.h:33
rmw_context_t
rcl_context_t::RCL_ALIGNAS
RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]
Private storage for instance ID atomic.
rcl_arguments_t
Hold output of parsing command line arguments.
Definition: arguments.h:32
rcl_context_t
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:108