rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__CONTEXT_HPP_
16 #define RCLCPP__CONTEXT_HPP_
18 #include <condition_variable>
25 #include <unordered_map>
29 #include "rcl/context.h"
30 #include "rcl/guard_condition.h"
48 class WeakContextsWrapper;
115 char const *
const argv[],
308 template<
typename SubContext,
typename ... Args>
316 auto it = sub_contexts_.
find(type_i);
317 if (it == sub_contexts_.
end()) {
320 new SubContext(std::forward<Args>(args) ...),
321 [](SubContext * sub_context_ptr) {
322 delete sub_context_ptr;
324 sub_contexts_[type_i] = sub_context;
327 sub_context = std::static_pointer_cast<SubContext>(it->second);
367 std::mutex interrupt_guard_cond_handles_mutex_;
385 #endif // RCLCPP__CONTEXT_HPP_
const std::vector< OnShutdownCallback > & get_on_shutdown_callbacks() const
Return the shutdown callbacks as const.
Context()
Default constructor, after which the Context is still not "initialized".
virtual OnShutdownCallback on_shutdown(OnShutdownCallback callback)
Add a on_shutdown callback to be called when shutdown is called for this context.
virtual void interrupt_all_wait_sets()
Interrupt any blocking executors, or wait sets associated with this context.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
rcl_guard_condition_t * get_interrupt_guard_condition(rcl_wait_set_t *wait_set)
Get a handle to the guard condition which is triggered when interrupted.
virtual void interrupt_all_sleep_for()
Interrupt any blocking sleep_for calls, causing them to return immediately and return true.
virtual void init(int argc, char const *const argv[], const rclcpp::InitOptions &init_options=rclcpp::InitOptions())
Initialize the context, and the underlying elements like the rcl context.
std::string shutdown_reason()
Return the shutdown reason, or empty string if not shutdown.
const rclcpp::InitOptions & get_init_options() const
Return the init options used during init.
Thrown when init is called on an already initialized context.
Definition: context.hpp:40
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
ContextAlreadyInitialized()
Definition: context.hpp:43
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
bool is_valid() const
Return true if the context is valid, otherwise false.
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
bool sleep_for(const std::chrono::nanoseconds &nanoseconds)
Sleep for a given period of time or until shutdown() is called.
Encapsulation of options for initializing rclcpp.
Definition: init_options.hpp:27
Context which encapsulates shared state between nodes and other similar entities.
Definition: context.hpp:56
std::shared_ptr< rcl_context_t > get_rcl_context()
Return the internal rcl context.
virtual bool shutdown(const std::string &reason)
Shutdown the context, making it uninitialized and therefore invalid for derived entities.
void release_interrupt_guard_condition(rcl_wait_set_t *wait_set)
Release the previously allocated guard condition which is triggered when interrupted.
std::vector< Context::SharedPtr > get_contexts()
Return a copy of the list of context shared pointers.
std::shared_ptr< SubContext > get_sub_context(Args &&... args)
Return a singleton instance for the SubContext type, constructing one if necessary.
Definition: context.hpp:310