.. _program_listing_file_include_rclcpp_lifecycle_lifecycle_node.hpp: Program Listing for File lifecycle_node.hpp =========================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/rclcpp_lifecycle/lifecycle_node.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2016 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 RCLCPP_LIFECYCLE__LIFECYCLE_NODE_HPP_ #define RCLCPP_LIFECYCLE__LIFECYCLE_NODE_HPP_ #include #include #include #include #include #include #include #include "rcutils/macros.h" #include "rcl/error_handling.h" #include "rcl/node.h" #include "rcl_interfaces/msg/list_parameters_result.hpp" #include "rcl_interfaces/msg/parameter_descriptor.hpp" #include "rcl_interfaces/msg/set_parameters_result.hpp" #include "rclcpp/callback_group.hpp" #include "rclcpp/client.hpp" #include "rclcpp/clock.hpp" #include "rclcpp/event.hpp" #include "rclcpp/generic_publisher.hpp" #include "rclcpp/generic_subscription.hpp" #include "rclcpp/logger.hpp" #include "rclcpp/macros.hpp" #include "rclcpp/message_memory_strategy.hpp" #include "rclcpp/node_options.hpp" #include "rclcpp/node_interfaces/node_base_interface.hpp" #include "rclcpp/node_interfaces/node_clock_interface.hpp" #include "rclcpp/node_interfaces/node_graph_interface.hpp" #include "rclcpp/node_interfaces/node_logging_interface.hpp" #include "rclcpp/node_interfaces/node_parameters_interface.hpp" #include "rclcpp/node_interfaces/node_services_interface.hpp" #include "rclcpp/node_interfaces/node_time_source_interface.hpp" #include "rclcpp/node_interfaces/node_timers_interface.hpp" #include "rclcpp/node_interfaces/node_topics_interface.hpp" #include "rclcpp/node_interfaces/node_type_descriptions_interface.hpp" #include "rclcpp/node_interfaces/node_waitables_interface.hpp" #include "rclcpp/parameter.hpp" #include "rclcpp/publisher.hpp" #include "rclcpp/publisher_options.hpp" #include "rclcpp/qos.hpp" #include "rclcpp/service.hpp" #include "rclcpp/subscription.hpp" #include "rclcpp/subscription_options.hpp" #include "rclcpp/time.hpp" #include "rclcpp/timer.hpp" #include "rmw/types.h" #include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp" #include "rclcpp_lifecycle/lifecycle_publisher.hpp" #include "rclcpp_lifecycle/state.hpp" #include "rclcpp_lifecycle/transition.hpp" #include "rclcpp_lifecycle/visibility_control.h" namespace rclcpp_lifecycle { // include these here to work around an esoteric Windows error where the namespace // cannot be used in the function declaration below without getting an error like: // 'rclcpp::SubscriptionOptionsWithAllocator': // no appropriate default constructor available template using PublisherOptionsWithAllocator = rclcpp::PublisherOptionsWithAllocator; template using SubscriptionOptionsWithAllocator = rclcpp::SubscriptionOptionsWithAllocator; template PublisherOptionsWithAllocator create_default_publisher_options() { return rclcpp::PublisherOptionsWithAllocator(); } template SubscriptionOptionsWithAllocator create_default_subscription_options() { return rclcpp::SubscriptionOptionsWithAllocator(); } class LifecycleNode : public node_interfaces::LifecycleNodeInterface, public std::enable_shared_from_this { public: RCLCPP_SMART_PTR_DEFINITIONS(LifecycleNode) RCLCPP_LIFECYCLE_PUBLIC explicit LifecycleNode( const std::string & node_name, const rclcpp::NodeOptions & options = rclcpp::NodeOptions(), bool enable_communication_interface = true); RCLCPP_LIFECYCLE_PUBLIC LifecycleNode( const std::string & node_name, const std::string & namespace_, const rclcpp::NodeOptions & options = rclcpp::NodeOptions(), bool enable_communication_interface = true); RCLCPP_LIFECYCLE_PUBLIC virtual ~LifecycleNode(); RCLCPP_LIFECYCLE_PUBLIC const char * get_name() const; RCLCPP_LIFECYCLE_PUBLIC const char * get_namespace() const; RCLCPP_LIFECYCLE_PUBLIC const char * get_fully_qualified_name() const; RCLCPP_LIFECYCLE_PUBLIC rclcpp::Logger get_logger() const; RCLCPP_LIFECYCLE_PUBLIC rclcpp::CallbackGroup::SharedPtr create_callback_group( rclcpp::CallbackGroupType group_type, bool automatically_add_to_executor_with_node = true); RCLCPP_LIFECYCLE_PUBLIC void for_each_callback_group( const rclcpp::node_interfaces::NodeBaseInterface::CallbackGroupFunction & func); template> std::shared_ptr> create_publisher( const std::string & topic_name, const rclcpp::QoS & qos, const PublisherOptionsWithAllocator & options = ( create_default_publisher_options() ) ); template< typename MessageT, typename CallbackT, typename AllocatorT = std::allocator, typename SubscriptionT = rclcpp::Subscription, typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType> std::shared_ptr create_subscription( const std::string & topic_name, const rclcpp::QoS & qos, CallbackT && callback, const SubscriptionOptionsWithAllocator & options = create_default_subscription_options(), typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = ( MessageMemoryStrategyT::create_default() ) ); template typename rclcpp::WallTimer::SharedPtr create_wall_timer( std::chrono::duration period, CallbackT callback, rclcpp::CallbackGroup::SharedPtr group = nullptr); template typename rclcpp::GenericTimer::SharedPtr create_timer( std::chrono::duration period, CallbackT callback, rclcpp::CallbackGroup::SharedPtr group = nullptr); template [[deprecated("use rclcpp::QoS instead of rmw_qos_profile_t")]] typename rclcpp::Client::SharedPtr create_client( const std::string & service_name, const rmw_qos_profile_t & qos_profile, rclcpp::CallbackGroup::SharedPtr group = nullptr); template typename rclcpp::Client::SharedPtr create_client( const std::string & service_name, const rclcpp::QoS & qos = rclcpp::ServicesQoS(), rclcpp::CallbackGroup::SharedPtr group = nullptr); template [[deprecated("use rclcpp::QoS instead of rmw_qos_profile_t")]] typename rclcpp::Service::SharedPtr create_service( const std::string & service_name, CallbackT && callback, const rmw_qos_profile_t & qos_profile, rclcpp::CallbackGroup::SharedPtr group = nullptr); template typename rclcpp::Service::SharedPtr create_service( const std::string & service_name, CallbackT && callback, const rclcpp::QoS & qos = rclcpp::ServicesQoS(), rclcpp::CallbackGroup::SharedPtr group = nullptr); template> std::shared_ptr create_generic_publisher( const std::string & topic_name, const std::string & topic_type, const rclcpp::QoS & qos, const rclcpp::PublisherOptionsWithAllocator & options = ( rclcpp::PublisherOptionsWithAllocator() ) ); template> std::shared_ptr create_generic_subscription( const std::string & topic_name, const std::string & topic_type, const rclcpp::QoS & qos, std::function)> callback, const rclcpp::SubscriptionOptionsWithAllocator & options = ( rclcpp::SubscriptionOptionsWithAllocator() ) ); RCLCPP_LIFECYCLE_PUBLIC const rclcpp::ParameterValue & declare_parameter( const std::string & name, const rclcpp::ParameterValue & default_value, const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor = rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override = false); RCLCPP_LIFECYCLE_PUBLIC const rclcpp::ParameterValue & declare_parameter( const std::string & name, rclcpp::ParameterType type, const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor = rcl_interfaces::msg::ParameterDescriptor{}, bool ignore_override = false); template auto declare_parameter( const std::string & name, const ParameterT & default_value, const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor = rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override = false); template auto declare_parameter( const std::string & name, const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor = rcl_interfaces::msg::ParameterDescriptor(), bool ignore_override = false); template std::vector declare_parameters( const std::string & namespace_, const std::map & parameters); template std::vector declare_parameters( const std::string & namespace_, const std::map< std::string, std::pair > & parameters); RCLCPP_LIFECYCLE_PUBLIC void undeclare_parameter(const std::string & name); RCLCPP_LIFECYCLE_PUBLIC bool has_parameter(const std::string & name) const; RCLCPP_LIFECYCLE_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameter(const rclcpp::Parameter & parameter); RCLCPP_LIFECYCLE_PUBLIC std::vector set_parameters(const std::vector & parameters); RCLCPP_LIFECYCLE_PUBLIC rcl_interfaces::msg::SetParametersResult set_parameters_atomically(const std::vector & parameters); RCLCPP_LIFECYCLE_PUBLIC rclcpp::Parameter get_parameter(const std::string & name) const; RCLCPP_LIFECYCLE_PUBLIC bool get_parameter( const std::string & name, rclcpp::Parameter & parameter) const; template bool get_parameter(const std::string & name, ParameterT & parameter) const; template bool get_parameter_or( const std::string & name, ParameterT & value, const ParameterT & alternative_value) const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_parameters(const std::vector & names) const; template bool get_parameters( const std::string & prefix, std::map & values) const; RCLCPP_LIFECYCLE_PUBLIC rcl_interfaces::msg::ParameterDescriptor describe_parameter(const std::string & name) const; RCLCPP_LIFECYCLE_PUBLIC std::vector describe_parameters(const std::vector & names) const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_parameter_types(const std::vector & names) const; RCLCPP_LIFECYCLE_PUBLIC rcl_interfaces::msg::ListParametersResult list_parameters(const std::vector & prefixes, uint64_t depth) const; using PreSetParametersCallbackHandle = rclcpp::node_interfaces::PreSetParametersCallbackHandle; using PreSetParametersCallbackType = rclcpp::node_interfaces::NodeParametersInterface::PreSetParametersCallbackType; using OnSetParametersCallbackHandle = rclcpp::node_interfaces::OnSetParametersCallbackHandle; using OnSetParametersCallbackType = rclcpp::node_interfaces::NodeParametersInterface::OnSetParametersCallbackType; using OnParametersSetCallbackType [[deprecated("use OnSetParametersCallbackType instead")]] = OnSetParametersCallbackType; using PostSetParametersCallbackHandle = rclcpp::node_interfaces::PostSetParametersCallbackHandle; using PostSetParametersCallbackType = rclcpp::node_interfaces::NodeParametersInterface::PostSetParametersCallbackType; RCLCPP_LIFECYCLE_PUBLIC RCUTILS_WARN_UNUSED rclcpp_lifecycle::LifecycleNode::PreSetParametersCallbackHandle::SharedPtr add_pre_set_parameters_callback( rclcpp_lifecycle::LifecycleNode::PreSetParametersCallbackType callback); RCLCPP_LIFECYCLE_PUBLIC RCUTILS_WARN_UNUSED rclcpp_lifecycle::LifecycleNode::OnSetParametersCallbackHandle::SharedPtr add_on_set_parameters_callback( rclcpp_lifecycle::LifecycleNode::OnSetParametersCallbackType callback); RCLCPP_LIFECYCLE_PUBLIC RCUTILS_WARN_UNUSED rclcpp_lifecycle::LifecycleNode::PostSetParametersCallbackHandle::SharedPtr add_post_set_parameters_callback( rclcpp_lifecycle::LifecycleNode::PostSetParametersCallbackType callback); RCLCPP_LIFECYCLE_PUBLIC void remove_pre_set_parameters_callback( const rclcpp_lifecycle::LifecycleNode::PreSetParametersCallbackHandle * const handler); RCLCPP_LIFECYCLE_PUBLIC void remove_on_set_parameters_callback( const rclcpp_lifecycle::LifecycleNode::OnSetParametersCallbackHandle * const handler); RCLCPP_LIFECYCLE_PUBLIC void remove_post_set_parameters_callback( const rclcpp_lifecycle::LifecycleNode::PostSetParametersCallbackHandle * const handler); RCLCPP_LIFECYCLE_PUBLIC std::vector get_node_names() const; RCLCPP_LIFECYCLE_PUBLIC std::map> get_topic_names_and_types(bool no_demangle = false) const; RCLCPP_LIFECYCLE_PUBLIC std::map> get_service_names_and_types() const; RCLCPP_LIFECYCLE_PUBLIC std::map> get_service_names_and_types_by_node( const std::string & node_name, const std::string & namespace_) const; RCLCPP_LIFECYCLE_PUBLIC size_t count_publishers(const std::string & topic_name) const; RCLCPP_LIFECYCLE_PUBLIC size_t count_subscribers(const std::string & topic_name) const; RCLCPP_LIFECYCLE_PUBLIC size_t count_clients(const std::string & service_name) const; RCLCPP_LIFECYCLE_PUBLIC size_t count_services(const std::string & service_name) const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_publishers_info_by_topic(const std::string & topic_name, bool no_mangle = false) const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_subscriptions_info_by_topic(const std::string & topic_name, bool no_mangle = false) const; /* The graph Event object is a loan which must be returned. * The Event object is scoped and therefore to return the load just let it go * out of scope. */ RCLCPP_LIFECYCLE_PUBLIC rclcpp::Event::SharedPtr get_graph_event(); /* The given Event must be acquire through the get_graph_event() method. * * \throws InvalidEventError if the given event is nullptr * \throws EventNotRegisteredError if the given event was not acquired with * get_graph_event(). */ RCLCPP_LIFECYCLE_PUBLIC void wait_for_graph_change( rclcpp::Event::SharedPtr event, std::chrono::nanoseconds timeout); RCLCPP_LIFECYCLE_PUBLIC rclcpp::Clock::SharedPtr get_clock(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::Clock::ConstSharedPtr get_clock() const; RCLCPP_LIFECYCLE_PUBLIC rclcpp::Time now() const; RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeClockInterface::SharedPtr get_node_clock_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeGraphInterface::SharedPtr get_node_graph_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr get_node_logging_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeTimersInterface::SharedPtr get_node_timers_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr get_node_topics_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeServicesInterface::SharedPtr get_node_services_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeParametersInterface::SharedPtr get_node_parameters_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr get_node_time_source_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr get_node_type_descriptions_interface(); RCLCPP_LIFECYCLE_PUBLIC rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr get_node_waitables_interface(); RCLCPP_LIFECYCLE_PUBLIC const rclcpp::NodeOptions & get_node_options() const; // // LIFECYCLE COMPONENTS // RCLCPP_LIFECYCLE_PUBLIC const State & get_current_state() const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_available_states() const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_available_transitions() const; RCLCPP_LIFECYCLE_PUBLIC std::vector get_transition_graph() const; /* * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & trigger_transition(const Transition & transition); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & trigger_transition( const Transition & transition, LifecycleNodeInterface::CallbackReturn & cb_return_code); /* * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & trigger_transition(uint8_t transition_id); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & trigger_transition( uint8_t transition_id, LifecycleNodeInterface::CallbackReturn & cb_return_code); /* * \param[out] cb_return_code transition callback return code. * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & configure(); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & configure(LifecycleNodeInterface::CallbackReturn & cb_return_code); /* * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & cleanup(); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & cleanup(LifecycleNodeInterface::CallbackReturn & cb_return_code); /* * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & activate(); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & activate(LifecycleNodeInterface::CallbackReturn & cb_return_code); /* * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & deactivate(); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & deactivate(LifecycleNodeInterface::CallbackReturn & cb_return_code); /* * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & shutdown(); /* * \param[out] cb_return_code transition callback return code * \return the new state after this transition */ RCLCPP_LIFECYCLE_PUBLIC const State & shutdown(LifecycleNodeInterface::CallbackReturn & cb_return_code); RCLCPP_LIFECYCLE_PUBLIC bool register_on_configure(std::function fcn); RCLCPP_LIFECYCLE_PUBLIC bool register_on_cleanup(std::function fcn); RCLCPP_LIFECYCLE_PUBLIC bool register_on_shutdown(std::function fcn); RCLCPP_LIFECYCLE_PUBLIC bool register_on_activate(std::function fcn); RCLCPP_LIFECYCLE_PUBLIC bool register_on_deactivate(std::function fcn); RCLCPP_LIFECYCLE_PUBLIC bool register_on_error(std::function fcn); RCLCPP_LIFECYCLE_PUBLIC CallbackReturn on_activate(const State & previous_state) override; RCLCPP_LIFECYCLE_PUBLIC CallbackReturn on_deactivate(const State & previous_state) override; protected: RCLCPP_LIFECYCLE_PUBLIC void add_managed_entity(std::weak_ptr managed_entity); RCLCPP_LIFECYCLE_PUBLIC void add_timer_handle(std::shared_ptr timer); private: RCLCPP_DISABLE_COPY(LifecycleNode) rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_; rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_; rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_; rclcpp::node_interfaces::NodeTimersInterface::SharedPtr node_timers_; rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_; rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_; rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_; rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_; rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr node_time_source_; rclcpp::node_interfaces::NodeTypeDescriptionsInterface::SharedPtr node_type_descriptions_; rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr node_waitables_; const rclcpp::NodeOptions node_options_; class LifecycleNodeInterfaceImpl; std::unique_ptr impl_; }; } // namespace rclcpp_lifecycle #ifndef RCLCPP_LIFECYCLE__LIFECYCLE_NODE_IMPL_HPP_ // Template implementations #include "rclcpp_lifecycle/lifecycle_node_impl.hpp" #endif #endif // RCLCPP_LIFECYCLE__LIFECYCLE_NODE_HPP_