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 
16 
17 #ifndef RCL__CONTEXT_H_
18 #define RCL__CONTEXT_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "rmw/init.h"
26 
27 #include "rcl/allocator.h"
28 #include "rcl/arguments.h"
29 #include "rcl/init_options.h"
30 #include "rcl/macros.h"
31 #include "rcl/types.h"
32 #include "rcl/visibility_control.h"
33 
35 #ifdef _MSC_VER
36 #define RCL_ALIGNAS(N) __declspec(align(N))
37 #else
38 #include <stdalign.h>
39 #define RCL_ALIGNAS(N) alignas(N)
40 #endif
41 
44 typedef uint64_t rcl_context_instance_id_t;
45 
46 struct rcl_context_impl_t;
47 
49 
113 typedef struct rcl_context_t
114 {
116 
118 
120  struct rcl_context_impl_t * impl;
121 
122  // The assumption that this is big enough for an atomic_uint_least64_t is
123  // ensured with a static_assert in the context.c file.
124  // In most cases it should just be a plain uint64_t.
126 #if !defined(RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE)
127 #define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE sizeof(uint_least64_t)
128 #endif
129 
149  RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE];
150 } rcl_context_t;
151 
153 RCL_PUBLIC
154 RCL_WARN_UNUSED
157 
159 
182 RCL_PUBLIC
183 RCL_WARN_UNUSED
184 rcl_ret_t
186 
188 
214 RCL_PUBLIC
215 RCL_WARN_UNUSED
216 const rcl_init_options_t *
218 
220 
242 RCL_PUBLIC
243 RCL_WARN_UNUSED
246 
248 
268 RCL_PUBLIC
269 RCL_WARN_UNUSED
270 rcl_ret_t
271 rcl_context_get_domain_id(rcl_context_t * context, size_t * domain_id);
272 
274 
290 RCL_PUBLIC
291 RCL_WARN_UNUSED
292 bool
293 rcl_context_is_valid(const rcl_context_t * context);
294 
296 
312 RCL_PUBLIC
313 RCL_WARN_UNUSED
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 
321 #endif // RCL__CONTEXT_H_
rcl_context_get_domain_id
rcl_ret_t rcl_context_get_domain_id(rcl_context_t *context, size_t *domain_id)
Returns the context domain id.
rcl_get_zero_initialized_context
rcl_context_t rcl_get_zero_initialized_context(void)
Return a zero initialization context object.
rcl_context_t::global_arguments
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Definition: context.h:117
rcl_context_t::impl
struct rcl_context_impl_t * impl
Implementation specific pointer.
Definition: context.h:120
rcl_context_instance_id_t
uint64_t rcl_context_instance_id_t
A unique ID per context instance.
Definition: context.h:44
types.h
rcl_ret_t
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:23
rcl_context_get_rmw_context
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_fini
rcl_ret_t rcl_context_fini(rcl_context_t *context)
Finalize a context.
rcl_context_get_instance_id
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.
init.h
rcl_context_get_init_options
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.
rcl_init_options_t
Encapsulation of init options and implementation defined init options.
Definition: init_options.h:35
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:35
arguments.h
init_options.h
allocator.h
rcl_context_t
Encapsulates the non-global state of an init/shutdown cycle.
Definition: context.h:113
rcl_context_is_valid
bool rcl_context_is_valid(const rcl_context_t *context)
Return true if the given context is currently valid, otherwise false.