Program Listing for File context.h

Return to documentation for file (include/rcl/context.h)

   |               |
+--> uninitialized +---> rcl_get_zero_initialized_context() +
|  |               |                                        |
|  +---------------+                                        |
|                                                           |
|           +-----------------------------------------------+
|           |
|  +--------v---------+                +-----------------------+
|  |                  |                |                       |
|  | zero-initialized +-> rcl_init() +-> initialized and valid +-> rcl_shutdown() +
|  |                  |                |                       |                  |
|  +------------------+                +-----------------------+                  |
|                                                                                 |
|               +-----------------------------------------------------------------+
|               |
|  +------------v------------+
|  |                         |
|  | initialized but invalid +---> finalize all entities, then rcl_context_fini() +
|  |                         |                                                    |
|  +-------------------------+                                                    |
|                                                                                 |
+---------------------------------------------------------------------------------+
// Copyright 2018 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


#ifndef RCL__CONTEXT_H_
#define RCL__CONTEXT_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "rmw/init.h"

#include "rcl/allocator.h"
#include "rcl/arguments.h"
#include "rcl/init_options.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"

#ifdef _MSC_VER
#define RCL_ALIGNAS(N) __declspec(align(N))
#else
#include <stdalign.h>
#define RCL_ALIGNAS(N) alignas(N)
#endif

typedef uint64_t rcl_context_instance_id_t;

typedef struct rcl_context_impl_s rcl_context_impl_t;


typedef struct rcl_context_s
{

  rcl_arguments_t global_arguments;

  rcl_context_impl_t * impl;

  // The assumption that this is big enough for an atomic_uint_least64_t is
  // ensured with a static_assert in the context.c file.
  // In most cases it should just be a plain uint64_t.
#if !defined(RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE)
#define RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE sizeof(uint_least64_t)
#endif

  RCL_ALIGNAS(8) uint8_t instance_id_storage[RCL_CONTEXT_ATOMIC_INSTANCE_ID_STORAGE_SIZE];
} rcl_context_t;

RCL_PUBLIC
RCL_WARN_UNUSED
rcl_context_t
rcl_get_zero_initialized_context(void);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_context_fini(rcl_context_t * context);


RCL_PUBLIC
RCL_WARN_UNUSED
const rcl_init_options_t *
rcl_context_get_init_options(const rcl_context_t * context);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_context_instance_id_t
rcl_context_get_instance_id(const rcl_context_t * context);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_context_get_domain_id(rcl_context_t * context, size_t * domain_id);


RCL_PUBLIC
RCL_WARN_UNUSED
bool
rcl_context_is_valid(const rcl_context_t * context);


RCL_PUBLIC
RCL_WARN_UNUSED
rmw_context_t *
rcl_context_get_rmw_context(rcl_context_t * context);

#ifdef __cplusplus
}
#endif

#endif  // RCL__CONTEXT_H_