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>
26 #include <unordered_set>
49 class WeakContextsWrapper;
127 char const *
const argv[],
288 template<
typename SubContext,
typename ... Args>
296 auto it = sub_contexts_.
find(type_i);
297 if (it == sub_contexts_.
end()) {
300 new SubContext(std::forward<Args>(args) ...),
301 [](SubContext * sub_context_ptr) {
302 delete sub_context_ptr;
304 sub_contexts_[type_i] = sub_context;
307 sub_context = std::static_pointer_cast<SubContext>(it->second);
339 mutable std::mutex on_shutdown_callbacks_mutex_;
360 #endif // RCLCPP__CONTEXT_HPP_
size_t get_domain_id() const
Return actual domain id.
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 bool remove_on_shutdown_callback(const OnShutdownCallbackHandle &callback_handle)
Remove an registered on_shutdown callbacks.
std::vector< OnShutdownCallback > get_on_shutdown_callbacks() const
Return the shutdown callbacks.
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::function< void()> OnShutdownCallbackType
Definition: context.hpp:56
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.
Definition: context.hpp:51
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:41
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
virtual OnShutdownCallbackHandle add_on_shutdown_callback(OnShutdownCallback callback)
Add a on_shutdown callback to be called when shutdown is called for this context.
ContextAlreadyInitialized()
Definition: context.hpp:44
#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:28
Context which encapsulates shared state between nodes and other similar entities.
Definition: context.hpp:68
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.
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:290
std::string shutdown_reason() const
Return the shutdown reason, or empty string if not shutdown.