Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make lifecycle impl get_current_state() const. #2031

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface,
*/
RCLCPP_LIFECYCLE_PUBLIC
const State &
get_current_state();
get_current_state() const;

/// Return a list with the available states.
/**
Expand Down
2 changes: 1 addition & 1 deletion rclcpp_lifecycle/src/lifecycle_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ LifecycleNode::register_on_error(
}

const State &
LifecycleNode::get_current_state()
LifecycleNode::get_current_state() const
{
return impl_->get_current_state();
}
Expand Down
15 changes: 13 additions & 2 deletions rclcpp_lifecycle/src/lifecycle_node_interface_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ LifecycleNode::LifecycleNodeInterfaceImpl::init(bool enable_communication_interf
nullptr);
}
}

current_state_ = State(state_machine_.current_state);
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
}

bool
Expand Down Expand Up @@ -327,9 +329,8 @@ LifecycleNode::LifecycleNodeInterfaceImpl::on_get_transition_graph(
}

const State &
LifecycleNode::LifecycleNodeInterfaceImpl::get_current_state()
LifecycleNode::LifecycleNodeInterfaceImpl::get_current_state() const
{
current_state_ = State(state_machine_.current_state);
return current_state_;
}

Expand Down Expand Up @@ -396,6 +397,9 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
return RCL_RET_ERROR;
}

// Update the internal current_state_
current_state_ = State(state_machine_.current_state);

auto get_label_for_return_code =
[](node_interfaces::LifecycleNodeInterface::CallbackReturn cb_return_code) -> const char *{
auto cb_id = static_cast<uint8_t>(cb_return_code);
Expand All @@ -421,6 +425,9 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
return RCL_RET_ERROR;
}

// Update the internal current_state_
current_state_ = State(state_machine_.current_state);

// error handling ?!
// TODO(karsten1987): iterate over possible ret value
if (cb_return_code == node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR) {
Expand All @@ -437,6 +444,10 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
return RCL_RET_ERROR;
}
}

// Update the internal current_state_
current_state_ = State(state_machine_.current_state);

// This true holds in both cases where the actual callback
// was successful or not, since at this point we have a valid transistion
// to either a new primary state or error state
Expand Down
2 changes: 1 addition & 1 deletion rclcpp_lifecycle/src/lifecycle_node_interface_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LifecycleNode::LifecycleNodeInterfaceImpl final
std::function<node_interfaces::LifecycleNodeInterface::CallbackReturn(const State &)> & cb);

const State &
get_current_state();
get_current_state() const;

std::vector<State>
get_available_states() const;
Expand Down