rename RCL_LIFECYCLE_RET_T to lifecycle_msgs::msgs::Transition::TRANSITION_CALLBACK_* (#345)
This commit is contained in:
parent
a41245e6bf
commit
9281e32f82
8 changed files with 156 additions and 116 deletions
|
@ -245,40 +245,51 @@ LifecycleNode::get_node_parameters_interface()
|
|||
|
||||
////
|
||||
bool
|
||||
LifecycleNode::register_on_configure(std::function<rcl_lifecycle_ret_t(const State &)> fcn)
|
||||
LifecycleNode::register_on_configure(
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)> fcn)
|
||||
{
|
||||
return impl_->register_callback(lifecycle_msgs::msg::State::TRANSITION_STATE_CONFIGURING, fcn);
|
||||
return impl_->register_callback(
|
||||
lifecycle_msgs::msg::State::TRANSITION_STATE_CONFIGURING, fcn);
|
||||
}
|
||||
|
||||
bool
|
||||
LifecycleNode::register_on_cleanup(std::function<rcl_lifecycle_ret_t(const State &)> fcn)
|
||||
LifecycleNode::register_on_cleanup(
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)> fcn)
|
||||
{
|
||||
return impl_->register_callback(lifecycle_msgs::msg::State::TRANSITION_STATE_CLEANINGUP, fcn);
|
||||
return impl_->register_callback(
|
||||
lifecycle_msgs::msg::State::TRANSITION_STATE_CLEANINGUP, fcn);
|
||||
}
|
||||
|
||||
bool
|
||||
LifecycleNode::register_on_shutdown(std::function<rcl_lifecycle_ret_t(const State &)> fcn)
|
||||
LifecycleNode::register_on_shutdown(
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)> fcn)
|
||||
{
|
||||
return impl_->register_callback(lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN, fcn);
|
||||
return impl_->register_callback(
|
||||
lifecycle_msgs::msg::State::TRANSITION_STATE_SHUTTINGDOWN, fcn);
|
||||
}
|
||||
|
||||
bool
|
||||
LifecycleNode::register_on_activate(std::function<rcl_lifecycle_ret_t(const State &)> fcn)
|
||||
LifecycleNode::register_on_activate(
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)> fcn)
|
||||
{
|
||||
return impl_->register_callback(lifecycle_msgs::msg::State::TRANSITION_STATE_ACTIVATING, fcn);
|
||||
return impl_->register_callback(
|
||||
lifecycle_msgs::msg::State::TRANSITION_STATE_ACTIVATING, fcn);
|
||||
}
|
||||
|
||||
bool
|
||||
LifecycleNode::register_on_deactivate(std::function<rcl_lifecycle_ret_t(const State &)> fcn)
|
||||
LifecycleNode::register_on_deactivate(
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)> fcn)
|
||||
{
|
||||
return impl_->register_callback(lifecycle_msgs::msg::State::TRANSITION_STATE_DEACTIVATING, fcn);
|
||||
return impl_->register_callback(
|
||||
lifecycle_msgs::msg::State::TRANSITION_STATE_DEACTIVATING, fcn);
|
||||
}
|
||||
|
||||
bool
|
||||
LifecycleNode::register_on_error(std::function<rcl_lifecycle_ret_t(const State &)> fcn)
|
||||
LifecycleNode::register_on_error(
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)> fcn)
|
||||
{
|
||||
return impl_->register_callback(lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING,
|
||||
fcn);
|
||||
return impl_->register_callback(
|
||||
lifecycle_msgs::msg::State::TRANSITION_STATE_ERRORPROCESSING, fcn);
|
||||
}
|
||||
|
||||
const State &
|
||||
|
@ -307,7 +318,7 @@ LifecycleNode::trigger_transition(const Transition & transition)
|
|||
|
||||
const State &
|
||||
LifecycleNode::trigger_transition(
|
||||
const Transition & transition, rcl_lifecycle_ret_t & cb_return_code)
|
||||
const Transition & transition, rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return trigger_transition(transition.id(), cb_return_code);
|
||||
}
|
||||
|
@ -320,7 +331,7 @@ LifecycleNode::trigger_transition(uint8_t transition_id)
|
|||
|
||||
const State &
|
||||
LifecycleNode::trigger_transition(
|
||||
uint8_t transition_id, rcl_lifecycle_ret_t & cb_return_code)
|
||||
uint8_t transition_id, rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return impl_->trigger_transition(transition_id, cb_return_code);
|
||||
}
|
||||
|
@ -333,7 +344,7 @@ LifecycleNode::configure()
|
|||
}
|
||||
|
||||
const State &
|
||||
LifecycleNode::configure(rcl_lifecycle_ret_t & cb_return_code)
|
||||
LifecycleNode::configure(rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return impl_->trigger_transition(
|
||||
lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE, cb_return_code);
|
||||
|
@ -347,7 +358,7 @@ LifecycleNode::cleanup()
|
|||
}
|
||||
|
||||
const State &
|
||||
LifecycleNode::cleanup(rcl_lifecycle_ret_t & cb_return_code)
|
||||
LifecycleNode::cleanup(rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return impl_->trigger_transition(
|
||||
lifecycle_msgs::msg::Transition::TRANSITION_CLEANUP, cb_return_code);
|
||||
|
@ -361,7 +372,7 @@ LifecycleNode::activate()
|
|||
}
|
||||
|
||||
const State &
|
||||
LifecycleNode::activate(rcl_lifecycle_ret_t & cb_return_code)
|
||||
LifecycleNode::activate(rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return impl_->trigger_transition(
|
||||
lifecycle_msgs::msg::Transition::TRANSITION_ACTIVATE, cb_return_code);
|
||||
|
@ -375,7 +386,7 @@ LifecycleNode::deactivate()
|
|||
}
|
||||
|
||||
const State &
|
||||
LifecycleNode::deactivate(rcl_lifecycle_ret_t & cb_return_code)
|
||||
LifecycleNode::deactivate(rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return impl_->trigger_transition(
|
||||
lifecycle_msgs::msg::Transition::TRANSITION_DEACTIVATE, cb_return_code);
|
||||
|
@ -389,7 +400,7 @@ LifecycleNode::shutdown()
|
|||
}
|
||||
|
||||
const State &
|
||||
LifecycleNode::shutdown(rcl_lifecycle_ret_t & cb_return_code)
|
||||
LifecycleNode::shutdown(rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
return impl_->trigger_transition(
|
||||
lifecycle_msgs::msg::Transition::TRANSITION_SHUTDOWN, cb_return_code);
|
||||
|
|
|
@ -164,7 +164,7 @@ public:
|
|||
}
|
||||
|
||||
bool
|
||||
register_callback(std::uint8_t lifecycle_transition, std::function<rcl_lifecycle_ret_t(
|
||||
register_callback(std::uint8_t lifecycle_transition, std::function<rcl_lifecycle_transition_key_t(
|
||||
const State &)> & cb)
|
||||
{
|
||||
cb_map_[lifecycle_transition] = cb;
|
||||
|
@ -181,7 +181,7 @@ public:
|
|||
throw std::runtime_error(
|
||||
"Can't get state. State machine is not initialized.");
|
||||
}
|
||||
rcl_lifecycle_ret_t cb_return_code;
|
||||
rcl_lifecycle_transition_key_t cb_return_code;
|
||||
auto ret = change_state(req->transition.id, cb_return_code);
|
||||
(void) ret;
|
||||
// TODO(karsten1987): Lifecycle msgs have to be extended to keep both returns
|
||||
|
@ -281,7 +281,7 @@ public:
|
|||
}
|
||||
|
||||
rcl_ret_t
|
||||
change_state(std::uint8_t lifecycle_transition, rcl_lifecycle_ret_t & cb_return_code)
|
||||
change_state(std::uint8_t lifecycle_transition, rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
if (rcl_lifecycle_state_machine_is_initialized(&state_machine_) != RCL_RET_OK) {
|
||||
RCUTILS_LOG_ERROR("Unable to change state for state machine for %s: %s",
|
||||
|
@ -312,11 +312,11 @@ public:
|
|||
|
||||
// error handling ?!
|
||||
// TODO(karsten1987): iterate over possible ret value
|
||||
if (cb_return_code == RCL_LIFECYCLE_RET_ERROR) {
|
||||
if (cb_return_code == lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_ERROR) {
|
||||
RCUTILS_LOG_WARN("Error occurred while doing error handling.")
|
||||
rcl_lifecycle_ret_t error_resolved = execute_callback(state_machine_.current_state->id,
|
||||
initial_state);
|
||||
if (error_resolved == RCL_LIFECYCLE_RET_OK) {
|
||||
rcl_lifecycle_transition_key_t error_resolved = execute_callback(
|
||||
state_machine_.current_state->id, initial_state);
|
||||
if (error_resolved == lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS) {
|
||||
// We call cleanup on the error state
|
||||
if (rcl_lifecycle_trigger_transition(&state_machine_, error_resolved, true) != RCL_RET_OK) {
|
||||
RCUTILS_LOG_ERROR("Failed to call cleanup on error state")
|
||||
|
@ -336,11 +336,12 @@ public:
|
|||
return RCL_RET_OK;
|
||||
}
|
||||
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
execute_callback(unsigned int cb_id, const State & previous_state)
|
||||
{
|
||||
// in case no callback was attached, we forward directly
|
||||
auto cb_success = RCL_LIFECYCLE_RET_OK;
|
||||
rcl_lifecycle_transition_key_t cb_success =
|
||||
lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
|
||||
|
||||
auto it = cb_map_.find(cb_id);
|
||||
if (it != cb_map_.end()) {
|
||||
|
@ -355,7 +356,7 @@ public:
|
|||
// fprintf(stderr, "Original error msg: %s\n", e.what());
|
||||
// maybe directly go for error handling here
|
||||
// and pass exception along with it
|
||||
cb_success = RCL_LIFECYCLE_RET_ERROR;
|
||||
cb_success = lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_ERROR;
|
||||
}
|
||||
}
|
||||
return cb_success;
|
||||
|
@ -364,14 +365,14 @@ public:
|
|||
const State &
|
||||
trigger_transition(uint8_t transition_id)
|
||||
{
|
||||
rcl_lifecycle_ret_t error;
|
||||
rcl_lifecycle_transition_key_t error;
|
||||
change_state(transition_id, error);
|
||||
(void) error;
|
||||
return get_current_state();
|
||||
}
|
||||
|
||||
const State &
|
||||
trigger_transition(uint8_t transition_id, rcl_lifecycle_ret_t & cb_return_code)
|
||||
trigger_transition(uint8_t transition_id, rcl_lifecycle_transition_key_t & cb_return_code)
|
||||
{
|
||||
change_state(transition_id, cb_return_code);
|
||||
return get_current_state();
|
||||
|
@ -393,7 +394,7 @@ public:
|
|||
State current_state_;
|
||||
std::map<
|
||||
std::uint8_t,
|
||||
std::function<rcl_lifecycle_ret_t(const State &)>> cb_map_;
|
||||
std::function<rcl_lifecycle_transition_key_t(const State &)>> cb_map_;
|
||||
|
||||
using NodeBasePtr = std::shared_ptr<rclcpp::node_interfaces::NodeBaseInterface>;
|
||||
using NodeServicesPtr = std::shared_ptr<rclcpp::node_interfaces::NodeServicesInterface>;
|
||||
|
|
|
@ -12,46 +12,48 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "lifecycle_msgs/msg/transition.hpp"
|
||||
|
||||
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
|
||||
|
||||
namespace rclcpp_lifecycle
|
||||
{
|
||||
namespace node_interfaces
|
||||
{
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
LifecycleNodeInterface::on_configure(const State &)
|
||||
{
|
||||
return RCL_LIFECYCLE_RET_OK;
|
||||
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
|
||||
}
|
||||
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
LifecycleNodeInterface::on_cleanup(const State &)
|
||||
{
|
||||
return RCL_LIFECYCLE_RET_OK;
|
||||
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
|
||||
}
|
||||
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
LifecycleNodeInterface::on_shutdown(const State &)
|
||||
{
|
||||
return RCL_LIFECYCLE_RET_OK;
|
||||
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
|
||||
}
|
||||
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
LifecycleNodeInterface::on_activate(const State &)
|
||||
{
|
||||
return RCL_LIFECYCLE_RET_OK;
|
||||
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
|
||||
}
|
||||
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
LifecycleNodeInterface::on_deactivate(const State &)
|
||||
{
|
||||
return RCL_LIFECYCLE_RET_OK;
|
||||
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_SUCCESS;
|
||||
}
|
||||
|
||||
rcl_lifecycle_ret_t
|
||||
rcl_lifecycle_transition_key_t
|
||||
LifecycleNodeInterface::on_error(const State &)
|
||||
{
|
||||
return RCL_LIFECYCLE_RET_FAILURE;
|
||||
return lifecycle_msgs::msg::Transition::TRANSITION_CALLBACK_FAILURE;
|
||||
}
|
||||
|
||||
} // namespace node_interfaces
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue