rcl  master
C API providing common ROS client library functionality.
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 
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 
150 
151 // See `rcl_init()` for initialization of the context.
152 
154 
177 rcl_ret_t
179 
180 // See `rcl_shutdown()` for invalidation of the context.
181 
183 
211 const rcl_init_options_t *
213 
215 
239 rcl_context_instance_id_t
241 
243 
261 bool
263 
265 
285 
286 #ifdef __cplusplus
287 }
288 #endif
289 
290 #endif // RCL__CONTEXT_H_
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...
rcl_context_t rcl_get_zero_initialized_context(void)
Return a zero initialization context object.
rcl_ret_t rcl_context_fini(rcl_context_t *context)
Finalize a context.
rmw_ret_t rcl_ret_t
Definition: types.h:20
Hold output of parsing command line arguments.
Definition: arguments.h:32
rcl_context_instance_id_t rcl_context_get_instance_id(rcl_context_t *context)
Returns an unsigned integer that is unique to the given context, or 0 if invalid. ...
const rcl_init_options_t * rcl_context_get_init_options(rcl_context_t *context)
Return the init options used during initialization for this context.
#define RCL_WARN_UNUSED
Ignored return values of functions with this macro will emit a warning.
Definition: macros.h:25
bool rcl_context_is_valid(rcl_context_t *context)
Return true if the given context is currently valid, otherwise false.
#define RCL_PUBLIC
Definition: visibility_control.h:48
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Definition: context.h:112
Encapsulation of init options and implementation defined init options.
Definition: init_options.h:33
struct rcl_context_impl_t * impl
Implementation specific pointer.
Definition: context.h:115
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:108
#define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE
Definition: context.h:121
RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE]
Private storage for instance ID atomic.
uint64_t rcl_context_instance_id_t
Definition: context.h:39