Skip to content

Commit

Permalink
adhere to new refactoring (#276)
Browse files Browse the repository at this point in the history
* adhere to new refactoring

* remove keys, transition id unique, label ambiguous

* semicolon for macro call
  • Loading branch information
Karsten1987 authored Oct 11, 2018
1 parent ec42432 commit bc1fbed
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions lifecycle/src/lifecycle_talker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
* TRANSITION_CALLBACK_FAILURE transitions to "unconfigured"
* TRANSITION_CALLBACK_ERROR or any uncaught exceptions to "errorprocessing"
*/
rcl_lifecycle_transition_key_t
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_configure(const rclcpp_lifecycle::State &)
{
// This callback is supposed to be used for initialization and
Expand All @@ -127,7 +127,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
// would stay in the "unconfigured" state.
// In case of TRANSITION_CALLBACK_ERROR or any thrown exception within
// this callback, the state machine transitions to state "errorprocessing".
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

/// Transition callback for state activating
Expand All @@ -141,7 +141,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
* TRANSITION_CALLBACK_FAILURE transitions to "inactive"
* TRANSITION_CALLBACK_ERROR or any uncaught exceptions to "errorprocessing"
*/
rcl_lifecycle_transition_key_t
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_activate(const rclcpp_lifecycle::State &)
{
// We explicitly activate the lifecycle publisher.
Expand All @@ -162,7 +162,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
// would stay in the "inactive" state.
// In case of TRANSITION_CALLBACK_ERROR or any thrown exception within
// this callback, the state machine transitions to state "errorprocessing".
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

/// Transition callback for state deactivating
Expand All @@ -176,7 +176,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
* TRANSITION_CALLBACK_FAILURE transitions to "active"
* TRANSITION_CALLBACK_ERROR or any uncaught exceptions to "errorprocessing"
*/
rcl_lifecycle_transition_key_t
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_deactivate(const rclcpp_lifecycle::State &)
{
// We explicitly deactivate the lifecycle publisher.
Expand All @@ -192,21 +192,21 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
// would stay in the "active" state.
// In case of TRANSITION_CALLBACK_ERROR or any thrown exception within
// this callback, the state machine transitions to state "errorprocessing".
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

/// Transition callback for state cleaningup
/**
* on_cleanup callback is being called when the lifecycle node
* enters the "cleaningup" state.
* Depending on the return value of this function, the state machine
* either invokes a transition to the "uncofigured" state or stays
* either invokes a transition to the "unconfigured" state or stays
* in "inactive".
* TRANSITION_CALLBACK_SUCCESS transitions to "unconfigured"
* TRANSITION_CALLBACK_FAILURE transitions to "inactive"
* TRANSITION_CALLBACK_ERROR or any uncaught exceptions to "errorprocessing"
*/
rcl_lifecycle_transition_key_t
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_cleanup(const rclcpp_lifecycle::State &)
{
// In our cleanup phase, we release the shared pointers to the
Expand All @@ -223,7 +223,41 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
// would stay in the "inactive" state.
// In case of TRANSITION_CALLBACK_ERROR or any thrown exception within
// this callback, the state machine transitions to state "errorprocessing".
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

/// Transition callback for state shutting down
/**
* on_shutdown callback is being called when the lifecycle node
* enters the "shuttingdown" state.
* Depending on the return value of this function, the state machine
* either invokes a transition to the "finalized" state or stays
* in its current state.
* TRANSITION_CALLBACK_SUCCESS transitions to "finalized"
* TRANSITION_CALLBACK_FAILURE transitions to current state
* TRANSITION_CALLBACK_ERROR or any uncaught exceptions to "errorprocessing"
*/
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_shutdown(const rclcpp_lifecycle::State & state)
{
// In our cleanup phase, we release the shared pointers to the
// timer and publisher. These entities are no longer available
// and our node is "clean".
timer_.reset();
pub_.reset();

RCUTILS_LOG_INFO_NAMED(
get_name(),
"on shutdown is called from state %s.",
state.label().c_str());

// We return a success and hence invoke the transition to the next
// step: "unconfigured".
// If we returned TRANSITION_CALLBACK_FAILURE instead, the state machine
// would stay in the "inactive" state.
// In case of TRANSITION_CALLBACK_ERROR or any thrown exception within
// this callback, the state machine transitions to state "errorprocessing".
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

private:
Expand Down

0 comments on commit bc1fbed

Please sign in to comment.