Add line break after first open paren in multiline function call (#785)

* Add line break after first open paren in multiline function call

as per developer guide:
https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#open-versus-cuddled-braces
see https://github.com/ament/ament_lint/pull/148

Signed-off-by: Dan Rose <dan@digilabs.io>

Fix dedent when first function argument starts with a brace

Signed-off-by: Dan Rose <dan@digilabs.io>

Line break with multiline if condition
Remove line breaks where allowed.

Signed-off-by: Dan Rose <dan@digilabs.io>

Fixup after rebase

Signed-off-by: Dan Rose <dan@digilabs.io>

Fixup again after reverting indent_paren_open_brace

Signed-off-by: Dan Rose <dan@digilabs.io>

* Revert comment spacing change, condense some lines

Signed-off-by: Dan Rose <dan@digilabs.io>
This commit is contained in:
Dan Rose 2019-08-07 10:33:06 -05:00 committed by Dirk Thomas
parent dc3c36c7f0
commit 4a5eed968c
41 changed files with 587 additions and 366 deletions

View file

@ -305,9 +305,7 @@ LifecycleNode::set_parameter_if_not_set(
{
rclcpp::Parameter parameter;
if (!this->get_parameter(name, parameter)) {
this->set_parameters({
rclcpp::Parameter(name, value),
});
this->set_parameters({rclcpp::Parameter(name, value), });
}
}
@ -376,9 +374,7 @@ LifecycleNode::get_parameter_or_set(
{
bool got_parameter = get_parameter(name, value);
if (!got_parameter) {
this->set_parameters({
rclcpp::Parameter(name, alternative_value),
});
this->set_parameters({rclcpp::Parameter(name, alternative_value), });
value = alternative_value;
}
}

View file

@ -83,7 +83,8 @@ public:
publish(std::unique_ptr<MessageT, MessageDeleter> msg)
{
if (!enabled_) {
RCLCPP_WARN(logger_,
RCLCPP_WARN(
logger_,
"Trying to publish message on the topic '%s', but the publisher is not activated",
this->get_topic_name());
@ -102,7 +103,8 @@ public:
publish(const MessageT & msg)
{
if (!enabled_) {
RCLCPP_WARN(logger_,
RCLCPP_WARN(
logger_,
"Trying to publish message on the topic '%s', but the publisher is not activated",
this->get_topic_name());
@ -130,7 +132,8 @@ public:
publish(const std::shared_ptr<const MessageT> & msg)
{
if (!enabled_) {
RCLCPP_WARN(logger_,
RCLCPP_WARN(
logger_,
"Trying to publish message on the topic '%s', but the publisher is not activated",
this->get_topic_name());

View file

@ -114,15 +114,23 @@ LifecycleNode::LifecycleNode(
{
impl_->init();
register_on_configure(std::bind(&LifecycleNodeInterface::on_configure, this,
std::placeholders::_1));
register_on_configure(
std::bind(
&LifecycleNodeInterface::on_configure, this,
std::placeholders::_1));
register_on_cleanup(std::bind(&LifecycleNodeInterface::on_cleanup, this, std::placeholders::_1));
register_on_shutdown(std::bind(&LifecycleNodeInterface::on_shutdown, this,
std::placeholders::_1));
register_on_activate(std::bind(&LifecycleNodeInterface::on_activate, this,
std::placeholders::_1));
register_on_deactivate(std::bind(&LifecycleNodeInterface::on_deactivate, this,
std::placeholders::_1));
register_on_shutdown(
std::bind(
&LifecycleNodeInterface::on_shutdown, this,
std::placeholders::_1));
register_on_activate(
std::bind(
&LifecycleNodeInterface::on_activate, this,
std::placeholders::_1));
register_on_deactivate(
std::bind(
&LifecycleNodeInterface::on_deactivate, this,
std::placeholders::_1));
register_on_error(std::bind(&LifecycleNodeInterface::on_error, this, std::placeholders::_1));
}

View file

@ -105,8 +105,9 @@ public:
}
{ // change_state
auto cb = std::bind(&LifecycleNodeInterfaceImpl::on_change_state, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto cb = std::bind(
&LifecycleNodeInterfaceImpl::on_change_state, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
rclcpp::AnyServiceCallback<ChangeStateSrv> any_cb;
any_cb.set(std::move(cb));
@ -120,8 +121,9 @@ public:
}
{ // get_state
auto cb = std::bind(&LifecycleNodeInterfaceImpl::on_get_state, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto cb = std::bind(
&LifecycleNodeInterfaceImpl::on_get_state, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
rclcpp::AnyServiceCallback<GetStateSrv> any_cb;
any_cb.set(std::move(cb));
@ -135,8 +137,9 @@ public:
}
{ // get_available_states
auto cb = std::bind(&LifecycleNodeInterfaceImpl::on_get_available_states, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto cb = std::bind(
&LifecycleNodeInterfaceImpl::on_get_available_states, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
rclcpp::AnyServiceCallback<GetAvailableStatesSrv> any_cb;
any_cb.set(std::move(cb));
@ -150,8 +153,9 @@ public:
}
{ // get_available_transitions
auto cb = std::bind(&LifecycleNodeInterfaceImpl::on_get_available_transitions, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto cb = std::bind(
&LifecycleNodeInterfaceImpl::on_get_available_transitions, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
rclcpp::AnyServiceCallback<GetAvailableTransitionsSrv> any_cb;
any_cb.set(std::move(cb));
@ -166,8 +170,9 @@ public:
}
{ // get_transition_graph
auto cb = std::bind(&LifecycleNodeInterfaceImpl::on_get_transition_graph, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
auto cb = std::bind(
&LifecycleNodeInterfaceImpl::on_get_transition_graph, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
rclcpp::AnyServiceCallback<GetAvailableTransitionsSrv> any_cb;
any_cb.set(std::move(cb));
@ -355,7 +360,8 @@ public:
change_state(std::uint8_t transition_id, LifecycleNodeInterface::CallbackReturn & 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",
RCUTILS_LOG_ERROR(
"Unable to change state for state machine for %s: %s",
node_base_interface_->get_name(), rcl_get_error_string().str);
return RCL_RET_ERROR;
}
@ -364,10 +370,12 @@ public:
// keep the initial state to pass to a transition callback
State initial_state(state_machine_.current_state);
if (rcl_lifecycle_trigger_transition_by_id(
if (
rcl_lifecycle_trigger_transition_by_id(
&state_machine_, transition_id, publish_update) != RCL_RET_OK)
{
RCUTILS_LOG_ERROR("Unable to start transition %u from current state %s: %s",
RCUTILS_LOG_ERROR(
"Unable to start transition %u from current state %s: %s",
transition_id, state_machine_.current_state->label, rcl_get_error_string().str);
return RCL_RET_ERROR;
}
@ -386,10 +394,12 @@ public:
cb_return_code = execute_callback(state_machine_.current_state->id, initial_state);
auto transition_label = get_label_for_return_code(cb_return_code);
if (rcl_lifecycle_trigger_transition_by_label(
if (
rcl_lifecycle_trigger_transition_by_label(
&state_machine_, transition_label, publish_update) != RCL_RET_OK)
{
RCUTILS_LOG_ERROR("Failed to finish transition %u. Current state is now: %s",
RCUTILS_LOG_ERROR(
"Failed to finish transition %u. Current state is now: %s",
transition_id, state_machine_.current_state->label);
return RCL_RET_ERROR;
}
@ -401,7 +411,8 @@ public:
auto error_cb_code = execute_callback(state_machine_.current_state->id, initial_state);
auto error_cb_label = get_label_for_return_code(error_cb_code);
if (rcl_lifecycle_trigger_transition_by_label(
if (
rcl_lifecycle_trigger_transition_by_label(
&state_machine_, error_cb_label, publish_update) != RCL_RET_OK)
{
RCUTILS_LOG_ERROR("Failed to call cleanup on error state");

View file

@ -65,7 +65,8 @@ TEST_F(TestCallbackExceptions, positive_on_error) {
auto test_node = std::make_shared<PositiveCallbackExceptionNode>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE)).id());
// check if all callbacks were successfully overwritten
EXPECT_EQ(2u, test_node->number_of_callbacks);
@ -110,7 +111,8 @@ TEST_F(TestCallbackExceptions, negative_on_error) {
auto test_node = std::make_shared<NegativeCallbackExceptionNode>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
EXPECT_EQ(State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE)).id());
// check if all callbacks were successfully overwritten
EXPECT_EQ(2u, test_node->number_of_callbacks);

View file

@ -143,15 +143,20 @@ TEST_F(TestDefaultStateMachine, trigger_transition) {
auto test_node = std::make_shared<EmptyLifecycleNode>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
ASSERT_EQ(State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
ASSERT_EQ(
State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE)).id());
ASSERT_EQ(State::PRIMARY_STATE_ACTIVE, test_node->trigger_transition(
ASSERT_EQ(
State::PRIMARY_STATE_ACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_ACTIVATE)).id());
ASSERT_EQ(State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
ASSERT_EQ(
State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_DEACTIVATE)).id());
ASSERT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
ASSERT_EQ(
State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CLEANUP)).id());
ASSERT_EQ(State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
ASSERT_EQ(
State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_UNCONFIGURED_SHUTDOWN)).id());
}
@ -187,15 +192,20 @@ TEST_F(TestDefaultStateMachine, good_mood) {
auto test_node = std::make_shared<MoodyLifecycleNode<GoodMood>>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
EXPECT_EQ(State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE)).id());
EXPECT_EQ(State::PRIMARY_STATE_ACTIVE, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_ACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_ACTIVATE)).id());
EXPECT_EQ(State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_DEACTIVATE)).id());
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CLEANUP)).id());
EXPECT_EQ(State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_UNCONFIGURED_SHUTDOWN)).id());
// check if all callbacks were successfully overwritten
@ -206,7 +216,8 @@ TEST_F(TestDefaultStateMachine, bad_mood) {
auto test_node = std::make_shared<MoodyLifecycleNode<BadMood>>("testnode");
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE)).id());
// check if all callbacks were successfully overwritten

View file

@ -137,27 +137,42 @@ public:
TEST_F(TestRegisterCustomCallbacks, custom_callbacks) {
auto test_node = std::make_shared<CustomLifecycleNode>("testnode");
test_node->register_on_configure(std::bind(&CustomLifecycleNode::on_custom_configure,
test_node.get(), std::placeholders::_1));
test_node->register_on_cleanup(std::bind(&CustomLifecycleNode::on_custom_cleanup,
test_node.get(), std::placeholders::_1));
test_node->register_on_shutdown(std::bind(&CustomLifecycleNode::on_custom_shutdown,
test_node.get(), std::placeholders::_1));
test_node->register_on_activate(std::bind(&CustomLifecycleNode::on_custom_activate,
test_node.get(), std::placeholders::_1));
test_node->register_on_deactivate(std::bind(&CustomLifecycleNode::on_custom_deactivate,
test_node.get(), std::placeholders::_1));
test_node->register_on_configure(
std::bind(
&CustomLifecycleNode::on_custom_configure,
test_node.get(), std::placeholders::_1));
test_node->register_on_cleanup(
std::bind(
&CustomLifecycleNode::on_custom_cleanup,
test_node.get(), std::placeholders::_1));
test_node->register_on_shutdown(
std::bind(
&CustomLifecycleNode::on_custom_shutdown,
test_node.get(), std::placeholders::_1));
test_node->register_on_activate(
std::bind(
&CustomLifecycleNode::on_custom_activate,
test_node.get(), std::placeholders::_1));
test_node->register_on_deactivate(
std::bind(
&CustomLifecycleNode::on_custom_deactivate,
test_node.get(), std::placeholders::_1));
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->get_current_state().id());
EXPECT_EQ(State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE)).id());
EXPECT_EQ(State::PRIMARY_STATE_ACTIVE, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_ACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_ACTIVATE)).id());
EXPECT_EQ(State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_INACTIVE, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_DEACTIVATE)).id());
EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_UNCONFIGURED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_CLEANUP)).id());
EXPECT_EQ(State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
EXPECT_EQ(
State::PRIMARY_STATE_FINALIZED, test_node->trigger_transition(
rclcpp_lifecycle::Transition(Transition::TRANSITION_UNCONFIGURED_SHUTDOWN)).id());
// check if all callbacks were successfully overwritten

View file

@ -60,12 +60,14 @@ TEST_F(TestStateMachineInfo, available_transitions) {
for (rclcpp_lifecycle::Transition & transition : available_transitions) {
EXPECT_FALSE(transition.label().empty());
EXPECT_TRUE(transition.start_state().id() <= 4 ||
EXPECT_TRUE(
transition.start_state().id() <= 4 ||
(transition.start_state().id() >= 10 &&
(transition.start_state().id() <= 15)));
EXPECT_FALSE(transition.start_state().label().empty());
EXPECT_TRUE(transition.goal_state().id() <= 4 ||
EXPECT_TRUE(
transition.goal_state().id() <= 4 ||
(transition.goal_state().id() >= 10 &&
(transition.goal_state().id() <= 15)));
EXPECT_FALSE(transition.goal_state().label().empty());