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
|
@ -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>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue